最近在开发过程中用到比较多的批处理让我感觉ADO.NET2.0的事务真的是方便,记得以前的都是:
SqlTransaction trans;

trans = con.BeginTransaction();
cmd.Transaction = trans;
try
{
    cmd.ExecuteNonQuery();
    trans.Commit();
}
catch(Exception e)
{
    trans.Rollback();
}
finally
{
    con.Close();
}
一大堆东西麻烦,看看MSDN中ADO.NET2.0里面的事务:
        }
这样做的好处就是事务的好处,避免做了第一步数据操作而第二步或者第三不没有做造成数据的不统一。
最后提醒下:要添加引用并using System.Transactions;

相关文章:

  • 2022-12-23
  • 2022-02-16
  • 2021-06-24
  • 2021-07-01
  • 2021-12-16
  • 2022-02-22
  • 2022-12-23
猜你喜欢
  • 2021-12-11
  • 2021-07-05
  • 2021-09-20
  • 2021-07-20
  • 2022-01-27
  • 2022-12-23
相关资源
相似解决方案