我有 Form1 和 Form2
Form1 我有一个禁用的按钮,但如果我单击 Form1 上的菜单条,我会转到 Form2。在 Form2 上,我登录到数据库。成功登录后,我希望 Form2 关闭,并且我希望 Form1 上的按钮启用。
这是我的代码:
private void button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection(@"...");
SqlCommand command = new SqlCommand("SELECT * FROM UserT WHERE UserName ='" +
textBox1.Text + "' AND password ='" +
textBox2.Text + "'",
connection);
connection.Open();
SqlDataReader reader = null;
reader = command.ExecuteReader();
if (reader.Read())
{
MessageBox.Show("Welcome " + reader["UserName"].ToString());
Form1 lfm = new Form1();
lfm.button1.Enabled = true;
Form2 fm = new Form2();
fm.Close();
}
else
{
MessageBox.Show("Username and password " +
textBox1.Text + "does not exist");
}
}