我有一个问题,我创建了一个可编辑的datagridview 每行中都有一个“更新”按钮 当我连续进行更改并按“更新”按钮时,它仅保存修改后的数据并拒绝所有数据
fox示例,如果客户从发票中退回了一些东西,因此只有行会保存在退回表中,我们在其中创建一些修改而拒绝其他修改
所以基本上我有两个问题; 1)如何检测数据网格中的更改 2),然后仅保存修改后的行!
这是我在datagrid中获取发票的代码 private void button1_Click(对象发送者,EventArgs e) {
string query = @"Select Item.ItemName as item, Stock.SalePrice as
Price, invoice.Qty
FROM invoice
JOIN item ON invoice.ItemID = item.ItemID
JOIN sale ON invoice.SaleID = sale.SaleID
join Stock on Stock.ItemID = item.ItemID
where sale.SaleID = '" + textBox1.Text + "'";
SqlDataAdapter SDA = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
SDA.Fill(dt);
dataGridView1.DataSource = dt;
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn);
btn.HeaderText = "Update";
btn.Text = "Update";
btn.Name = "btnUpdate";
btn.UseColumnTextForButtonValue = true;
}
但是当我对数量进行编辑并按“更新”按钮时,它将保存所有我没有的datagidview数据
private void dataGridView1_CellValueChanged(object sender,
DataGridViewCellEventArgs e)
{
for (int j = 0; j < dataGridView1.Rows.Count; j++)
{
String Query = @"INSERT INTO b_bsale(b_bsale.item_id,
b_bsale.sale_price, b_bsale.qty) VALUES ('" + 1 + "','" + 33 +
"','" + dataGridView1.Rows[j].Cells[2].Value + "')";
SqlDataAdapter SDA = new SqlDataAdapter(Query, con);
con.Open();
SDA.SelectCommand.ExecuteNonQuery();
con.Close();
MessageBox.Show("Succesfully Data Entered!", "Congragulation!",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
我只想保存已编辑的数据并拒绝所有未编辑的数据