Advertisement
Guest User

Untitled

a guest
May 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. using System.Configuration;
  8.  
  9. public class CategoryDB
  10. {
  11. public static SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);
  12. public static List<Category> getAllCategories()
  13. {
  14. List<Category> categories = new List<Category>();
  15. try
  16. {
  17. SqlCommand command = new SqlCommand("Select * from Category");
  18. command.Connection = connection;
  19. connection.Open();
  20. SqlDataReader reader = command.ExecuteReader();
  21. while (reader.Read())
  22. {
  23. categories.Add(new Category(reader["name"].ToString(), reader["description"].ToString()));
  24. }
  25. reader.Close();
  26. }
  27. finally
  28. {
  29. connection.Close();
  30. }
  31. return categories;
  32.  
  33.  
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement