Я работаю с небольшим приложением (инвентаризация), в котором есть несколько кнопок для сетки данных, которая извлекает данные из базы данных SQL.Когда я получаю данные из SQL в сетке данных, у меня есть четыре столбца, например, например:
Code Product Qty Price Total
123456789 Coke 1 0.8 0.8
Всего столбца выражения ia (Кол-во * Цена) Что я хочу сделать, когда пользователь меняет количество с 1 на 2и он нажимает кнопку, чтобы сохранить данные из таблицы данных, которые должны быть сохранены в другой таблице в базе данных, а также количество выбранного продукта должно вычитаться, например, от 40 до 38. Может ли кто-нибудь мне помочь, я застрял здесь
if (e.Key == Key.Enter)
{ SqlConnection con = new SqlConnection("Server = localhost;Database
= Bilanc; Integrated Security = true"); SqlCommand cmd = new
SqlCommand("Product", con); // Using a Store Procedure.
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("Barcode", txtcode.Text);
dtg.ItemsSource = dataTable.DefaultView;//Set the DataGrid
ItemSource to this new generated DataTable
con.Open();//Open the SQL connection
SqlDataReader reader = cmd.ExecuteReader();//Create a SqlDataReader
while (reader.Read())//For each row that the SQL query returns do
{
DataRow dr = dataTable.NewRow();//Create new DataRow to populate the
DataTable (which is currently binded to the DataGrid)
dr[0] = reader[0];//Fill DataTable column 0 current row (Product) with
reader[0] (Product from sql)
dr[1] = reader[1];
dr[2] = reader[2];
dr[3] = reader[3];
dataTable.Rows.Add(dr);//Add the new created DataRow to the DataTable
txtkodi.Text = "";
object sumObject;
sumObject = dataTable.Compute("Sum(Total)", "");
txttot.Text = sumObject.ToString();
}