【发布时间】:2015-01-15 17:10:20
【问题描述】:
我正在做一个简单的 wpf 项目。共有三种形式,第一是登录表,第二是注册表,第三是个人资料表。项目要求是当我在注册页面上注册任何用户时,它会将我重定向到个人资料表单并向我显示刚刚创建的用户的完整个人资料。
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter();
string cs = ConfigurationManager.ConnectionStrings["CS"].ConnectionString;
if (txtUsername.Text == "" ||
txtPasswd.Text == "" ||
txtName.Text == "" ||
txtEmail.Text == "" ||
txtMobile.Text == ""
)
{
MessageBox.Show("Please fill the empty fields", "Warning");
}
else
{
using (SqlConnection con = new SqlConnection(cs))
{
string queryString = "Insert Into tblLogin Values(@Username,@Password,@Name,@Email,@Mobile)";
if (!Regex.IsMatch(txtEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
{
MessageBox.Show("Please enter a valid email", "Error");
}
else
{
da.InsertCommand = new SqlCommand(queryString, con);
da.InsertCommand.Parameters.Add("@Username", SqlDbType.NVarChar, 100).Value = txtUsername.Text;
da.InsertCommand.Parameters.Add("@Password", SqlDbType.NVarChar, 100).Value = txtPasswd.Text;
da.InsertCommand.Parameters.Add("@Name", SqlDbType.VarChar, 100).Value = txtName.Text;
da.InsertCommand.Parameters.Add("@Email", SqlDbType.NVarChar, 100).Value = txtEmail.Text;
da.InsertCommand.Parameters.Add("@Mobile", SqlDbType.NVarChar, 100).Value = txtMobile.Text;
con.Open();
da.InsertCommand.ExecuteNonQuery();
MessageBox.Show("Registration completed");
}
}
完成注册后,我想在另一个页面上显示刚刚创建的用户个人资料。谁能帮助我如何做到这一点。任何帮助都会非常感激。
【问题讨论】: