Tuesday, 11 June 2013

Logic to check username and Password

code to  check username and Password


You can do it in following way :
  1. SqlDataAdapter objAdpt;
  2. SqlConnection objCon = new SqlConnectin("your database connection string");
  3. DataTable objDt;
  4. now in the Click event of Button say "OK" button click event..
  5. objAdpt = new SqlDataAdapter("Select * from yourtablename WHERE UserID=' " + textBox1.Text.Trim() + " ' , Password = ' " + textBox2.Text.Trim() + " ' ", objCon);
  6. objDt = new DataTable();
  7. objAdpt.Fill(objDt);
  8. if(objDt.Rows.Count > 0)
  9. {
  10. lblmsg.Text="you are Login";
  11. Response.Redirect("home.aspx");
  12. // valid user. allow user to use system..
  13. }
  14. else
  15. {
  16. lblmsg.Text="Invalid Login";
  17. Response.Redirect("Login.aspx");
  18. // put message that invalid user..
  19. }

No comments:

Post a Comment