Mufid Bagdadi

Mufid Bagdadi

  • 2k
  • 146
  • 19.1k

if statement c# & sql...

May 20 2016 6:45 AM
Following is my code my requirement is after  if my password is rpgls007 it should redirect to particular page else to other page when data is read from database,
 
con.Open();
string strQuery = "select * from empData where empid = @username and password = @password";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@username", txtuser.Text.Trim());
cmd.Parameters.AddWithValue("@password", txtpassword.Text.Trim());
cmd.Connection = con;
dr = cmd.ExecuteReader();

if (dr.Read())
{
if (txtpassword.Text != "rpgls007")
{
Session["user"] = txtuser.Text;
Response.Redirect("user/user.aspx");
}
else
{
Session["user"] = txtuser.Text;
Response.Redirect("user/password.aspx");
}
}
else
{
lbl_msg.Text = "Incorrect User or Password";
resetPassword.Visible = true;
lbl_msg.Visible = true;
}

Answers (5)