Advertisement
Guest User

Untitled

a guest
Apr 7th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. public bool IsValid(string username, string password)
  2. {
  3.  
  4.  
  5. string conString = "Server= EJ ; Database=OnlineShopDb ; Integrated Security=SSPI";
  6.  
  7.  
  8. {
  9. SqlCommand cmd = new SqlCommand("Select * from dbo.UserTb where UserName=@UserName and PassWord=@PassWord");
  10. SqlConnection con = new SqlConnection(conString);
  11.  
  12. cmd.Parameters.AddWithValue("@UserName", SqlDbType.VarChar).Value = username;
  13. cmd.Parameters.AddWithValue("@PassWord", SqlDbType.VarChar).Value = password;
  14. con.Open();
  15. var reader = cmd.ExecuteReader();
  16. if (reader.HasRows)
  17. {
  18. reader.Dispose();
  19. cmd.Dispose();
  20. return true;
  21. }
  22. else
  23. {
  24. reader.Dispose();
  25. cmd.Dispose();
  26. return false;
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement