Guest User

Untitled

a guest
Feb 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. List<Notifications> listOfNotifications = new List<Notifications>();
  2. string sql =
  3. "SELECT [Id], [Read], [Message], [Url], [Updated], [Deleted], [DateCreated] FROM [Notifications] WHERE [FK_UserId] = @UserID";
  4. SqlConnection conn = new SqlConnection(connectionString);
  5. SqlCommand comm = new SqlCommand(sql, conn);
  6.  
  7. try
  8. {
  9. conn.Open();
  10. SqlDataReader reader;
  11. reader = comm.ExecuteReader();
  12. Notifications notification;
  13.  
  14. while (reader.Read())
  15. {
  16. notification = new Notifications();
  17. notification.Id = int.Parse(reader["Id"].ToString());
  18. notification.Read = bool.Parse(reader["Read"].ToString());
  19. notification.Message = reader["Message"].ToString();
  20. notification.Url = reader["Url"].ToString();
  21. notification.Updated = bool.Parse(reader["Updated"].ToString());
  22. notification.Deleted = bool.Parse(reader["Deleted"].ToString());
  23. notification.DateCreated = DateTime.Parse(reader["DateCreated"].ToString());
  24. listOfNotifications.Add(notification);
  25. }
  26.  
  27. }
  28. catch (Exception)
  29. {
  30.  
  31. throw;
  32. }
  33. finally
  34. {
  35. conn.Close();
  36. conn.Dispose();
  37. }
  38. return listOfNotifications;
  39. }
Add Comment
Please, Sign In to add comment