Venkata Subbareddy

Venkata Subbareddy

  • 960
  • 705
  • 95.5k

How to Login Two Table Users in a single Button using asp.ne

May 26 2015 10:08 AM
Hi Every one,
 Here Iam  creating Two tables in sql server when  student click the  submit button check the user crendtials in first table and when admin click the check the Admin Credtinals  .so here iam writing Code is perfectly working but i dont know how to insert the if statement . ....... any one let me where i do wrong in my code...
protected void BtnSubmit_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=SERVER;Initial Catalog=MuraliIIT;User ID=sa;Password=rits@1234");
SqlCommand cmd = new SqlCommand("select COUNT(*)FROM NewStudentRegistrationForm WHERE UserName='" + TxtUserName.Text + "' and password='" + Txtpassword.Text + "' and ApproveStatus=1");
cmd.Connection = conn;
conn.Open();
int OBJ = Convert.ToInt32(cmd.ExecuteScalar());
if (OBJ > 0)
{
Session["UserName"] = TxtUserName.Text;
// Response.Write("password is correct");
TxtUserName.Text = "";
Response.Flush();
Response.Redirect("StudentLoginSuccessfully.aspx");
}
else
{
Response.Write("<script type='text/javascript'>alert('Login Falid Please Enter your Correct UserName and Password.')</script>");
}
}
SqlConnection conn1 = new SqlConnection("Data Source=SERVER;Initial Catalog=MuraliIIT;User ID=sa;Password=rits@1234");
SqlCommand cmd1 = new SqlCommand("select COUNT(*)FROM Admin WHERE UserName='" + TxtUserName.Text + "' and password='" + Txtpassword.Text + "'");
cmd1.Connection = conn1;
conn1.Open();
int OBJ1 = Convert.ToInt32(cmd1.ExecuteScalar());
if (OBJ1 > 0)
{
Session["UserName"] = TxtUserName.Text;
// Response.Redirect("AdminAcceptstudents.aspx");
Response.Redirect("AdminAcceptstudents.aspx");
TxtUserName.Text = "";
}
}
 

Answers (3)