I have a login window in which the user should enter the user ID and password if the textBoxes are empty or the entered values are incorrect then the program should catch this showing an error message
I have written this code but it works only when the two textBoxes are empty whereas in the case of one of the textBoxes is empty or value entered for ID or password is incorrect the program stands with no reaction .. what is wrong with my codes .. regards
private void loginbtn_Click(object sender, EventArgs e)
{
try {
id = Convert.ToInt32(empIdtxt.Text);
cn.Open();
SqlCommand cmd = new SqlCommand("select empId,empPass from emp where empId='" + empIdtxt.Text + "' and empPass='" + passtxt.Text + "'", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
SqlCommand cmd2 = new SqlCommand("insert into empLogin (empId,empPerm) select empId,empPerm from emp where empId='" + empIdtxt.Text + "'", cn);
cmd2.ExecuteNonQuery();
MainFrm mainfrm = new MainFrm(id);
mainfrm.Show();
this.Hide();
}
}
catch
{
MessageBox.Show("User ID or password invalid or incorrect","Invalid ID or password",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
finally
{
cn.Close();
}