I have Form1 and Form2
Form1 I have a button that is disabled, but if I click on the menustrip on Form1 I go to Form2. On Form2 I log into a database. After I logged in successfully, I want Form2 to close and I want the button on Form1 to be enabled.
Here is my code:
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");
}
}