我希望在示例 c# 桌面应用程序 1 按钮插入数据中进行某种延迟回滚(不是批量回滚),另一个将其回滚
我尝试了以下但它不工作
error: The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
.
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConnectionString);
//conn = new SqlConnection(ConnectionString);
conn.Open();
try
{
//tran = conn.BeginTransaction("Transaction1");
SqlCommand cmd = new SqlCommand("begin transaction", conn);
SqlCommand cmd1 = new SqlCommand("insert into employee values ('6','aaaaaa','111')", conn);
cmd.ExecuteNonQuery();
cmd1.ExecuteNonQuery();
conn.Close();
}
catch { }
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
SqlCommand cmd2 = new SqlCommand("rollback transaction", conn);
cmd2.ExecuteNonQuery();
conn.Close();
}
我正在尝试的甚至可能吗?还是我只是走错路了?