How to show a message in label if entered values are incorrect
below is my code where ia m wrong i cant understanding actual problem is if i enter employee id and password and select hr its redirecting to next page but when selected employee it should display in label "incorrect id and pass word" but it showing like below and i have written code below once check where iam wrong""Conversion failed when converting the varchar value 'ravi' to data type int.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting the varchar value 'ravi' to data type int.
Source Error:
Line 51: cmd.Connection = con;
Line 52:
Line 53: int OBJ = Convert.ToInt32(cmd.ExecuteScalar());
Line 54:
Line 55: if (OBJ > 0)
code::::::::::::::::::::::::::::::::::::::
Session["uname"] = TextBox1.Text;
if (DropDownList1.SelectedItem.Text=="HR" && TextBox1.Text == "ravi" && TextBox2.Text == "123456")
{
Response.Redirect("HR.aspx");
}
else{
Label1.Text="please enter correct ID and Password";
Label1.Visible = true;
}
if (DropDownList1.SelectedItem.Text == "EMPLOYEE")
{
SqlConnection con = new SqlConnection(@"Data Source=ADMIN-PC;Initial Catalog=Registration;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select * FROM ekthaemployeeab WHERE EmployeeId ='" + TextBox1.Text + "' and Password='" + TextBox2.Text + "'");
cmd.Connection = con;
int OBJ = Convert.ToInt32(cmd.ExecuteNonQuery());
if (OBJ > 0)
{
Session["name"] = TextBox1.Text;
Response.RedirectPermanent("employeea.aspx");
}
else
{
Label1.Text = "please enter correct ID and Password";
}}