如何将DataTable中DataRowState的Added,Modified,Deleted分开AcceptChanges,出错后回滚?
1、如果使用
DataTable dtnew=DataTableOrg.GetChanges(DataRowState.Deleted)
dtnew.AcceptChanges(),只能更新DataTable.GetChanges得到的dtnew;
dtnew和DataTableOrg是2个独立,不能联动。
2、如果使用遍历更新,数据多的话,感觉效率有点低了。

解决方案 »

  1.   

    using (System.Transactions.TransactionScope updateTransaction = 
          new System.Transactions.TransactionScope())
      {
          // Add code to save your data here.
      
          // Throw an exception to roll back the transaction.
      
      
          // Call the Complete method to commit the transaction
      
          updateTransaction.Complete();
      }
      
    或者用 sqlclient 里的事务管理器
      

  2.   

    SqlTransaction transaction;
      

  3.   

    现在的问题是对DataTable 的AcceptChanges进行分开操作时有疑问。
    DataTable通过sql更新没有疑问,可以分开做。
      

  4.   

    GetChanges 创造的是复本,怎么可以联动呢
      

  5.   

    是2个独立的,现在就是想能不能实现类似联动的效果,把DataRowState的Added,Modified,Deleted分开AcceptChanges,出错后回滚,互不影响。
    用遍历的方式就是数据多时,效率差了。