如何在 sql 数据库的 wpf window 中显示特定用户数据?
How to display specific user data in wpf window from sql database?
我正在处理一个简单的 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");
}
}
完成注册后,我想显示刚刚创建的用户个人资料,但在另一个 page.Can 上,任何人都可以帮助我如何做 this.Any 非常感谢帮助。
我正在处理一个简单的 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");
}
}
完成注册后,我想显示刚刚创建的用户个人资料,但在另一个 page.Can 上,任何人都可以帮助我如何做 this.Any 非常感谢帮助。