注册 登录
编程论坛 新人交流区

C#中有关事务的问题

Lsx 发布于 2007-09-30 17:08, 572 次点击

请教各位!在C#中怎么引用事务!!!(希望能具体点)

5 回复
#2
kerr2007-09-30 17:23
例如点击事件?
#3
Lsx2007-09-30 17:41
不是!就是一个操作出错,,,他会全部回滚
#4
catherienxlj2007-09-30 18:46
回复:(Lsx)C#中有关事务的问题
SqlConnection conn = new SqlConnection(strConnection);
SqlTransaction transaction;
conn.Open();
SqlCommand command = conn.CreateCommand();
transaction = conn.BeginTransaction("RightTransaction");//这里可以改成你自己想写的
try
{
command.Connection = conn;
command.Transaction = transaction;
//这里是你要执行的语句;
transaction.commit();
}
catch (SqlException error)
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('" + error.Message + "');", true);//这里可用RESPONSE。WRITE(ERROR。MESSGE),如果你没用AJAX
try
{
transaction.Rollback();
}
catch (SqlException Innererror)
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('" + Innererror.Message + "');", true);
}
}
finally
{
conn.Close();
}
我也是从网上找到的,不知是否是你要用的。
#5
catherienxlj2007-09-30 18:47
回复:(catherienxlj)回复:(Lsx)C#中有关事务的问...
我自己用在程序里的
#6
Lsx2007-10-01 16:39

谢谢仁兄

1