如何在sql数据库的wpf窗口中显示特定的用户数据?

时间:2015-01-15 17:10:21

标签: c# sql wpf

我正在开发一个简单的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");
                    }

                }

完成注册后,我想显示刚刚创建的用户个人资料,但是在另一个页面上。任何人都可以帮我解决这个问题。任何帮助都会非常明显。

1 个答案:

答案 0 :(得分:0)

您需要阅读官方文档here。如果您阅读this并尝试this,那将会很有趣。

希望它有所帮助。

相关问题