IDatabase接口使用事务DbTransaction实例
作者:C/S框架网|www.cscode.ne  发布日期:2019/10/10 09:09:12
  IDatabase接口使用事务DbTransaction实例


DAL层代码参考:

C# Code:


/// <summary>
/// IDatabase接口使用事务实例
/// </summary>
public void TestTrans()
{
   //启用事务
   DbTransaction tran = _Database.TransBegin();
   try
   {
      
      string SQL1 = "delete dt_Employee where 1=0"; //脚本1
      _Database.ExecuteTrans(tran, SQL1);
      
      string SQL2 = "update dt_Employee set EmpName='' where 1=0";//脚本2
      _Database.ExecuteTrans(tran, SQL2);
      
      //提交事务
      tran.Commit();
   }
   catch
   {
      //回滚事务
      tran.Rollback();
   }
}

//来源:C/S框架网(www.csframework.com) QQ:23404761




上一篇 下一篇