private void button1_Click(object sender, EventArgs e) { if (txtUsername.Text == "" || txtPassword.Text == "") { MessageBox.Show("Please Provide Textbox Fields"); } else { if (buttonuser.Text == "Confirm") { try { con.Open(); cmd.Connection = con; cmd.CommandText = "SELECT* FROM usertbl WHERE username = '******' AND password = '******'"; dr = cmd.ExecuteReader(); if (dr.Read() == true) { MessageBox.Show("Login Successful"); ExamineeForm exam = new ExamineeForm(); exam.Show(); } else { MessageBox.Show("Username/password"); } } catch (Exception ex) { MessageBox.Show("Error Login User" + ex.ToString()); } finally { con.Close(); } } if (buttonuser.Text == "Login") { try { con.Open(); cmd.Connection = con; cmd.CommandText = "SELECT * FROM admintbl WHERE username = '******' AND password = '******'"; dr = cmd.ExecuteReader(); if (dr.Read() == true) { MessageBox.Show("Succesful login Admin"); MainAdmin admin = new MainAdmin(); admin.Show(); } else { MessageBox.Show("Invalid Username/Password"); } } catch (Exception ex) { MessageBox.Show("Error Login Admin" + ex.Message); } finally { con.Close(); } } } }