Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. /// <summary>
  2. /// Returns all the EmailAccount objects found in the database. If it is unable to do so,
  3. /// it logs the respective error to the error handler and returns a null object.
  4. /// </summary>
  5. /// <returns>A list of EmailAccount objects.</returns>
  6. public IEnumerable<EmailAccount> GetAll()
  7. {
  8. List<EmailAccount> allUsers = new List<EmailAccount>();
  9. try
  10. {
  11. using (SqlConnection connection = new SqlConnection(connectionString))
  12. using (SqlCommand command = new SqlCommand(sqlCommandGetAllUsers, connection))
  13. {
  14. SqlDataReader dataReader = null;
  15. connection.Open();
  16. dataReader = command.ExecuteReader();
  17. while (dataReader.HasRows && dataReader.Read())
  18. {
  19. EmailAccount user = new EmailAccount
  20. {
  21. UserId = dataReader.GetInt32(userIdColumn),
  22. EmailAddress = dataReader.GetString(emailAddressColumn),
  23. Password = dataReader.GetString(passwordColumn)
  24. };
  25. allUsers.Add(user);
  26. }
  27. connection.Close();
  28. }
  29. }
  30. catch (Exception x)
  31. {
  32. errorHandler.AddError(x);
  33. allUsers = null;
  34. }
  35. return allUsers;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement