Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Returns all the EmailAccount objects found in the database. If it is unable to do so,
- /// it logs the respective error to the error handler and returns a null object.
- /// </summary>
- /// <returns>A list of EmailAccount objects.</returns>
- public IEnumerable<EmailAccount> GetAll()
- {
- List<EmailAccount> allUsers = new List<EmailAccount>();
- try
- {
- using (SqlConnection connection = new SqlConnection(connectionString))
- using (SqlCommand command = new SqlCommand(sqlCommandGetAllUsers, connection))
- {
- SqlDataReader dataReader = null;
- connection.Open();
- dataReader = command.ExecuteReader();
- while (dataReader.HasRows && dataReader.Read())
- {
- EmailAccount user = new EmailAccount
- {
- UserId = dataReader.GetInt32(userIdColumn),
- EmailAddress = dataReader.GetString(emailAddressColumn),
- Password = dataReader.GetString(passwordColumn)
- };
- allUsers.Add(user);
- }
- connection.Close();
- }
- }
- catch (Exception x)
- {
- errorHandler.AddError(x);
- allUsers = null;
- }
- return allUsers;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement