예제 #1
0
        public void DeleteCategoryByName(string category)
        {
            int catid = reader.GetCategoryID(category);

            DeleteProductByCategory(catid);
            MySqlConnection conn = new MySqlConnection(ConnStr);

            using (conn)
            {
                conn.Open();

                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "DELETE FROM categories WHERE name = @category";
                cmd.Parameters.AddWithValue("category", category);
                cmd.ExecuteNonQuery();
            }
        }
예제 #2
0
        public void AddProduct(string name, decimal price, string category)
        {
            MySqlConnection conn = new MySqlConnection(ConnStr);

            int categoryID = reader.GetCategoryID(category);

            using (conn)
            {
                conn.Open();

                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "INSERT INTO products (Name, Price, CategoryID) VALUES(@name, @price, @categoryID);";
                cmd.Parameters.AddWithValue("name", name);
                cmd.Parameters.AddWithValue("price", price);
                cmd.Parameters.AddWithValue("categoryID", categoryID);
                cmd.ExecuteNonQuery();
            }
        }