代码如下:
//点击删除
private void delete_btn_Click(object sender, EventArgs e)
{
if (productId == -1)
{
MessageBox.Show("请先选择产品");
return;
}
MessageBox.Show(productId.toString());
DBHelper.conn.Open();
OleDbTransaction tran = DBHelper.conn.BeginTransaction();
string deleteProduct = string.Format(@"update product set p_delete_flag = 1 where p_id = {0}", productId);
OleDbCommand deleteProductCmd = new OleDbCommand(deleteProduct, DBHelper.conn);
deleteProductCmd.Transaction = tran;
string deleteRate = string.Format(@"update rate set r_delete_flag = 1 where r_p_id = {0}", productId);
OleDbCommand deleteRateCmd = new OleDbCommand(deleteRate, DBHelper.conn);
deleteRateCmd.Transaction = tran;
try
{
int a = deleteProductCmd.ExecuteNonQuery();
MessageBox.Show(a.ToString());
int b = deleteRateCmd.ExecuteNonQuery();
MessageBox.Show(b.ToString());
MessageBox.Show("删除成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
tran.Rollback();
}
finally
{
deleteProductCmd.Dispose();
deleteRateCmd.Dispose();
DBHelper.conn.Close();
}
}
productId = 21
a= 1 数据库确实是一行
b=2 数据库里确实存在两行
返回数据库一看。。。一点没变