Advertisement
Guest User

LoginDAO

a guest
Oct 31st, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public class LoginDAO
  2. {
  3. private Database myDatabase;
  4. private String myConnectionString;
  5.  
  6. public LoginDAO()
  7. {
  8. myConnectionString = @"Data Source=(LocalDB)\v11.0;
  9. AttachDbFilename=|DataDirectory|\Database.mdf;
  10. Integrated Security=True;Connect Timeout=30";
  11. myDatabase = new Database();
  12. }
  13.  
  14. public LoginRole GetLoginRole(string username, string password)
  15. {
  16. LoginRole loginRole = new LoginRole();
  17. IDataReader resultSet;
  18.  
  19. try
  20. {
  21.  
  22. myDatabase.Open(myConnectionString);
  23.  
  24. String sqlText = String.Format(
  25. @"SELECT role
  26. FROM rider
  27. WHERE username = '{0}' AND password = '{1}'", username, password);
  28.  
  29. resultSet = myDatabase.ExecuteQuery(sqlText);
  30.  
  31. if(resultSet.Read() == true)
  32. {
  33. loginRole.Role = (String)resultSet["role"];
  34. }
  35. return loginRole;
  36.  
  37. }
  38. catch (Exception)
  39. {
  40. return null;
  41. }
  42. finally
  43. {
  44. myDatabase.Close();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement