SqlTransaction trans;
trans = con.BeginTransaction();
cmd.Transaction = trans;
try
{
cmd.ExecuteNonQuery();
trans.Commit();
}
catch(Exception e)
{
trans.Rollback();
}
finally
{
con.Close();
}
================================
using System.Transactions;
//// <summary>
/// 事务测试方法-- Add by Teracy on 2007-09-09
/// </summary>
void TestTransaction()
{
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
options.Timeout = TransactionManager.DefaultTimeout;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
{
//数据操作第一步;
//数据操作第二步;
//数据操作第三步;
scope.Complete();
}
}