回复:(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();
}
我也是从网上找到的,不知是否是你要用的。