5
Answers

if statement c# & sql...

Mufid Bagdadi

Mufid Bagdadi

8y
357
1
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)