public Category GetCategoryById(int categoryId) { Collection <Category> cats; using (SqlConnection connection = this.GetConnection()) { connection.Open(); SqlCommand sc = new SqlCommand("GetCategoryById", connection); sc.CommandType = CommandType.StoredProcedure; sc.Parameters.AddWithValue("CategoryId", categoryId); using (SqlDataReader reader = sc.ExecuteReader()) { cats = SqlDataMap.CreateCategoriesFromReader(reader); } } if (cats.Count > 0) { return(cats[0]); } else { return(null); } }
public Collection <Category> GetAllCategories() { Collection <Category> cats; using (SqlConnection connection = this.GetConnection()) { connection.Open(); SqlCommand sc = new SqlCommand("GetAllCategories", connection); sc.CommandType = CommandType.StoredProcedure; using (SqlDataReader reader = sc.ExecuteReader()) { cats = SqlDataMap.CreateCategoriesFromReader(reader); } } return(cats); }