Hello guys.
I have 2 asp.net WebForms, WebForm1 contains a button that redirects into WebForm2 which contains a contact form that needs to be filled to proceed an order.
I have a drop down list in it that is connected to the database, and depending on which product a button on the WebForm1 is clicked, the current quantity is displayed from the specific product from the database.
After the ordering, I need to decrease/deduct the product quantity from the database depending on how many products on the drop down list were selected.
How to decrease the product quantity after the order is proceed?
Here is the code that takes the quantity from the DataBase:
string productName = Request.QueryString["productname"];
txt_product13.Text = productName;
var dictionary = new Dictionary<string, object>
{
{ "@ProductName", productName }
};
var parameters = new DynamicParameters(dictionary);
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (var connection = new SqlConnection(CS))
{
connection.Open();
var sql = "SELECT * FROM ProductsDB WHERE ProductName = @ProductName";
var product = connection.QuerySingle<Product>(sql, parameters);
// this applies the currency on the Price field.
CultureInfo EuroCulture = new CultureInfo("fr-FR");
txt_productprice.Text = product.Price.ToString("c", EuroCulture);
// this fills the Quantity drop drop down list.
for (int i = 1; i <= product.Quantity; i++)
{
dropdownlist1.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
}
}
For now, I have this code for decreasing but I can't get it why it does not decrease
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
string productName = Request.QueryString["productname"];
using (var connection = new SqlConnection(CS))
{
connection.Open();
var sql = "UPDATE ProductsDB SET Quantity = WHERE ProductName = @ProductName" + dropdownlist1.SelectedValue + "'";
connection.Close();
}
Any help is welcome, thank you.