Exemple #1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            //check duplicated
            string  ProductID   = txtProductID.Text;
            string  ProductName = txtProductName.Text;
            decimal CategoryID  = numCategoryID_Pro.Value;
            decimal Price       = numPrice.Value;

            checkDuplicate(ProductID);
            if (checkDuplicate(ProductID))
            {
                SqlConnection cnn        = new SqlConnection(cnn_str);
                SqlCommand    cmd_update = new SqlCommand();
                SqlParameter  pa_ProID   = new SqlParameter("@ProID", ProductID);
                SqlParameter  pa_ProName = new SqlParameter("@ProName", ProductName);
                SqlParameter  pa_Price   = new SqlParameter("@Price", Price);
                SqlParameter  pa_CateID  = new SqlParameter("@CateID", CategoryID);
                cmd_update.Connection  = cnn;
                cmd_update.CommandText = "Update_Product";
                cmd_update.CommandType = CommandType.StoredProcedure;
                cmd_update.Parameters.Add(pa_ProID);
                cmd_update.Parameters.Add(pa_ProName);
                cmd_update.Parameters.Add(pa_Price);
                cmd_update.Parameters.Add(pa_CateID);
                SqlCommandBuilder sqlCommand = new SqlCommandBuilder();
                da.SelectCommand = cmd_update;
                da.Update(ds, "tblProduct");
                da.Fill(ds, "tblProduct");
                if (ds.Tables["tblProduct"].Rows.Count > 0)
                {
                    MessageBox.Show("Cập nhật thành công");
                    Product_Management product_Management = new Product_Management();
                    product_Management.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Cập nhật thất bại");
                }
            }
            else
            {
                MessageBox.Show("Không tồn tại sản phẩm này");
            }
        }