Guest User

Untitled

a guest
Jan 19th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. public static SqlDataReader login(SchoolBAL bal)
  2. {
  3. SqlConnection con = DBConnection.OpenConnection();
  4. try
  5. {
  6. int i;
  7. SqlCommand cmd1 = new SqlCommand("login", con);
  8. cmd1.CommandType = CommandType.StoredProcedure;
  9. cmd1.Parameters.AddWithValue("@username", bal.UserName);
  10. cmd1.Parameters.AddWithValue("@password", bal.Password);
  11. SqlDataReader dr = cmd1.ExecuteReader();
  12. return dr;
  13. }catch (Exception)
  14. {
  15. throw;
  16. }
  17. }
  18.  
  19. Create procedure login
  20. (@username varchar (50),@password varchar (50))
  21.  
  22. as
  23. begin
  24. select UserName,password from tblLogin where UserName=@username and password=@password
  25. end
  26.  
  27. public static bool login(SchoolBAL bal)
  28. {
  29. bool isFound=false;
  30. using(SqlConnection con = DBConnection.OpenConnection())
  31. {
  32. using(SqlCommand cmd1 = new SqlCommand("login", con))
  33. {
  34. cmd1.CommandType = CommandType.StoredProcedure;
  35. cmd1.Parameters.AddWithValue("@username", bal.UserName);
  36. cmd1.Parameters.AddWithValue("@password", bal.Password);
  37. con.Open();
  38. SqlDataReader dr = cmd1.ExecuteReader();
  39. if(dr.Read())
  40. isFound=true;
  41. dr.Close();
  42. con.Close();
  43. }
  44. }
  45. return isFound;
  46. }
  47.  
  48. public static int login(SchoolBAL bal)
  49. {
  50. SqlConnection con = DBConnection.OpenConnection();
  51. try
  52. {
  53. int i;
  54. SqlCommand cmd1 = new SqlCommand("login", con);
  55. cmd1.CommandType = CommandType.StoredProcedure;
  56. cmd1.Parameters.AddWithValue("@username", bal.UserName);
  57. cmd1.Parameters.AddWithValue("@password", bal.Password);
  58. i = cmd1.ExecuteScalar();
  59. return i;
  60.  
  61. }
  62. catch (Exception)
  63. {
  64.  
  65. throw;
  66. }
  67. }
Add Comment
Please, Sign In to add comment