예제 #1
0
        public static List <Category> SearchName(string categoryName)
        {
            List <Category> foundCategories = new List <Category> {
            };
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("SELECT * FROM categories WHERE name LIKE @CategoryName", conn);

            cmd.Parameters.Add(new SqlParameter("@CategoryName", "%" + categoryName + "%"));
            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int      categoryId    = rdr.GetInt32(0);
                string   newName       = rdr.GetString(1);
                Category foundCategory = new Category(newName, categoryId);
                foundCategories.Add(foundCategory);
            }

            DB.CloseSqlConnection(conn, rdr);
            return(foundCategories);
        }
예제 #2
0
 public static void DeleteAll()
 {
     DB.DeleteAll("categories");
 }