i think this will help you....
if (cboRole.Text == "NORMAL USER")
{
try
{
objCon.Open();
SqlCommand objCom = new SqlCommand("SELECT * FROM LOGIN WHERE USERNAME='" + this.txtUserName.Text.Trim() + "' and PASSWORD='" + this.txtPassword.Text.Trim() + "' AND USER_ROLE='" + this.cboRole.Text.Trim() + "'", objCon);
SqlDataReader dr = objCom.ExecuteReader();
if (dr.HasRows)
{
MessageBox.Show("Login Successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
Form1 objForm = new Form1();
objForm.Show();
this.Hide();
}
else
{
MessageBox.Show("User Name or password is incorrect", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtUserName.Text = "";
txtPassword.Text = "";
txtUserName.Focus();
}
}
catch (SqlException er)
{
MessageBox.Show(er.Message);
}
finally
{
objCon.Close();
}
}
else if (cboRole.Text == "SUPER USER")
{
try
{
objCon.Open();
SqlCommand objCom = new SqlCommand("SELECT * FROM LOGIN WHERE USERNAME='" + this.txtUserName.Text.Trim() + "' and PASSWORD='" + this.txtPassword.Text.Trim() + "' AND USER_ROLE='" + this.cboRole.Text.Trim() + "'", objCon);
SqlDataReader dr = objCom.ExecuteReader();
if (dr.HasRows)
{
MessageBox.Show("Login Successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
Form1 objForm = new Form1();
objForm.Show();
this.Hide();
}
else
{
MessageBox.Show("User Name or password is incorrect", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtUserName.Text = "";
txtPassword.Text = "";
txtUserName.Focus();
}
}
catch (SqlException er)
{
MessageBox.Show(er.Message);
}
finally
{
objCon.Close();
}
}
else if (cboRole.Text == "ADMIN")
{
try
{
objCon.Open();
SqlCommand objCom = new SqlCommand("SELECT * FROM LOGIN WHERE USERNAME='" + this.txtUserName.Text.Trim() + "' AND PASSWORD='" + this.txtPassword.Text.Trim() + "' AND USER_ROLE='" + this.cboRole.Text.Trim() + "'", objCon);
SqlDataReader dr = objCom.ExecuteReader();
if (dr.HasRows)
{
MessageBox.Show("Login Successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.RetUserName = (string)txtUserName.Text;
Form1 objForm = new Form1();
objForm.Show();
this.Hide();
}
else
{
MessageBox.Show("User Name or password is incorrect", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtUserName.Text = "";
txtPassword.Text = "";
txtUserName.Focus();
}
}
catch (SqlException er)
{
MessageBox.Show(er.Message);
}
finally
{
objCon.Close();
}
}