Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<Notifications> listOfNotifications = new List<Notifications>();
- string sql =
- "SELECT [Id], [Read], [Message], [Url], [Updated], [Deleted], [DateCreated] FROM [Notifications] WHERE [FK_UserId] = @UserID";
- SqlConnection conn = new SqlConnection(connectionString);
- SqlCommand comm = new SqlCommand(sql, conn);
- try
- {
- conn.Open();
- SqlDataReader reader;
- reader = comm.ExecuteReader();
- Notifications notification;
- while (reader.Read())
- {
- notification = new Notifications();
- notification.Id = int.Parse(reader["Id"].ToString());
- notification.Read = bool.Parse(reader["Read"].ToString());
- notification.Message = reader["Message"].ToString();
- notification.Url = reader["Url"].ToString();
- notification.Updated = bool.Parse(reader["Updated"].ToString());
- notification.Deleted = bool.Parse(reader["Deleted"].ToString());
- notification.DateCreated = DateTime.Parse(reader["DateCreated"].ToString());
- listOfNotifications.Add(notification);
- }
- }
- catch (Exception)
- {
- throw;
- }
- finally
- {
- conn.Close();
- conn.Dispose();
- }
- return listOfNotifications;
- }
Add Comment
Please, Sign In to add comment