Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void btnSaveOut_Click(object sender, EventArgs e)
        {
            double tps = Convert.ToDouble(txtStockOut.Text) * Convert.ToDouble(txtPriceOut.Text);
            try
            {
                MySqlConnection con = new MySqlConnection("Server=localhost;UID=root;Database=db_cignal");
                con.Open();
                MySqlCommand command = con.CreateCommand();
                command.CommandText = "update inventoryOut set Model=@Model,Stock=@Stock,Date=@Date,Price=@Price,TotalPrice=@Total where Product=@Product";
                command.Parameters.AddWithValue("@Product", cbProductOut.SelectedItem.ToString());
                command.Parameters.AddWithValue("@Model", txtModelOut.Text);
                command.Parameters.AddWithValue("@Stock", txtStockOut.Text);
                command.Parameters.AddWithValue("@Date", DateTime.Now);
                command.Parameters.AddWithValue("@Price", txtPriceOut.Text);
                command.Parameters.AddWithValue("@Total", tps.ToString());
                command.Prepare();
                command.ExecuteNonQuery();
                BindGridInventoryOut();
                ClearFieldsinInventoryOUT();
                con.Close();
                MessageBox.Show("Saved!");
            }
            catch (Exception r)
            {
                MessageBox.Show(r.ToString());
            }
        }
Posted
Updated 11-Mar-15 23:13pm
v2
Comments
CHill60 12-Mar-15 5:16am    
It is not clear what your problem is.
Tomas Takac 12-Mar-15 5:18am    
You need to first read the product, update the values in C# then save the product. Or do it all in a stored proc but I would advise against that. Don't forget to put it all in one transaction!
Andy Lanng 12-Mar-15 6:56am    
This makes no sense:
If you have two products 'a' with stock of 1,2 and price 1 so total 1,2 then you update both 'a' & 'a' to show stock 3 and total 3. The next time you run this it will double ad infinitum.

You must be asking to get the total stock and total price AFTER making this update without changing the records? Then simply read the values out and sum them or use an aggregate SUM(x) in the query

Please clarify the problem
[edit spelling]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900