我试图在用户点击按钮(即保存按钮)时删除特定Aperture(Bussiness)的所有行,然后插入要保存的数据。代码如下:
private void button2_Click(object sender, EventArgs e)
{
SQLiteCommand cmdDel = new SQLiteCommand();
cmdDel = SQLconnect.CreateCommand();
cmdDel.CommandText = "DELETE FROM GridTable WHERE Aperturas=@combo";
cmdDel.Parameters.AddWithValue("@combo", combo1.Text);
cmdDel.ExecuteNonQuery();
DataTable dt = (DataTable)grid1.DataSource;
string sql = "INSERT INTO GridTable (Aperturas, Ventas, Proveedores, EAE, EAM) VALUES (@aperturas,@ventas,@proveedores,@eae,@eam)";
foreach (DataRow r in dt.Rows)
{
SQLiteCommand cmd = new SQLiteCommand();
cmd = SQLconnect.CreateCommand();
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("@aperturas", combo1.Text);
cmd.Parameters.AddWithValue("@ventas", r["Ventas"]);
cmd.Parameters.AddWithValue("@proveedores", r["Proveedores"]);
cmd.Parameters.AddWithValue("@eae", r["Egreso Axel Efectivo"]);
cmd.Parameters.AddWithValue("@eam", r["Egreso Axel Mercaderia"]);
cmd.ExecuteNonQuery();
}
}
问题是删除功能似乎没有做任何事情,当我加载数据时它显得重复,好像它已经插入第二次(它是,但不是最终显示那样)
提前谢谢。