SqlCommand cmd1 = new SqlCommand("IF (Select UnitsInStock from Products WHERE BarCode=@BarCode) > @Quantity BEGIN UPDATE Products SET UnitsInStock=(UnitsInStock-@Quantity) WHERE BarCode=@BarCode END ELSE BEGIN PRINT 'There are not enough items in stock'END", new SqlConnection(Program.ConnectionString)); cmd1.Connection.Open(); for (int i = 0; i < dtbProducts.Rows.Count; i++) { cmd1.Parameters.AddWithValue("Quantity", (int)dtbProducts.Rows[i]["Quantity"]); cmd1.Parameters.AddWithValue("BarCode", dtbProducts.Rows[i]["BarCode"].ToString()); cmd1.ExecuteNonQuery(); cmd1.Parameters.Clear(); } cmd1.Connection.Close(); cmd.Connection.Close(); this.Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)