所以在form1中我从我的数据库中选择数据,如果该数据与我在文本框中输入的数据相同,那么它将关闭表单并打开一个新数据。
con.Open();
SqlCommand command = new SqlCommand("select 1 from tblLogin where Username = @user and Securityquestion = @securityquestion and Answer = @answer", con);
command.Parameters.AddWithValue("@user", txtUsername.Text);
command.Parameters.AddWithValue("@securityqestion", ddlSecurityquestions.Text);
command.Parameters.AddWithValue("@answer", txtAnswer.Text);
var value = command.ExecuteScalar();
con.Close();
if (Object.Equals(value, 1))
{
this.Hide();
FormLoginWW2 ss = new FormLoginWW2();
ss.Show();
FormLoginWW2 objForm2 = new FormLoginWW2();
objForm2.ShowDialog();
string ret = objForm2.ReturnedText;
objForm2.ReturnedText = txtUsername.Text;
}
else
{
MessageBox.Show("Error");
}
这是form2。所以我想要的是我在form1中输入的用户名显示在标签内,以便我可以在数据库中更改该用户名的密码。
public string ReturnedText = "";
ReturnedText = labelUsername.Text;
SqlCommand command;
command = new SqlCommand("select * from tblLogin where Username = @user", con);
command.Parameters.AddWithValue("@user", labelUsername.Text);
if (txtPassword.Text == txtConfirmpassword.Text)
{
SqlCommand cmd = new SqlCommand("update tblLogin SET Password = @password where Username = @user ", con);
cmd.Parameters.AddWithValue("@password", txtPassword.Text);
MessageBox.Show("Success");
this.Hide();
FormLogin ss = new FormLogin();
ss.Show();
}
else
{
MessageBox.Show("Error.");
}
答案 0 :(得分:0)
in form1
public string txtsturen
{
get { return txtGebruikersnaam.Text; }
}
//按钮
FormLoginWW2 frm = new FormLoginWW2();
frm.txtsturen = txtsturen;
frm.Show();
this.Close();
in form2
public string txtsturen
{
set { labelGebruikersnaam.Text = value; }
}