Guest User

Untitled

a guest
Jun 5th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Data;
  9.  
  10. namespace finalproject
  11. {
  12. public partial class login : System.Web.UI.Page
  13. {
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16. lblErrorMessage.Visible = false;
  17. }
  18.  
  19. protected void btnLogin_Click(object sender, EventArgs e)
  20. {
  21. using (SqlConnection sqlcon = new SqlConnection("Data Source=DESKTOP-QMMKITS;Initial Catalog=login"))
  22. {
  23. sqlcon.Open();
  24. string query = "SELECT COUNT(1) FROM TableUser WHERE username=@username AND password=@password";
  25.  
  26. SqlCommand sqlCmd = new SqlCommand(query, sqlcon);
  27.  
  28. sqlCmd.Parameters.AddWithValue("@username", txtUserName.Text.Trim());
  29. sqlCmd.Parameters.AddWithValue("@password", txtPassword.Text.Trim());
  30.  
  31. int count = Convert.ToInt32(sqlCmd.ExecuteScalar());
  32.  
  33. if(count == 1)
  34. {
  35. Session["username"] = txtUserName.Text.Trim();
  36.  
  37. Response.Redirect("test.aspx");
  38. }
  39. else
  40. {
  41. lblErrorMessage.Visible = true;
  42. }
  43.  
  44. }
  45. }
  46. }
  47. }
Add Comment
Please, Sign In to add comment