如何将DataTable中DataRowState的Added,Modified,Deleted分开AcceptChanges,出错后回滚?
1、如果使用
DataTable dtnew=DataTableOrg.GetChanges(DataRowState.Deleted)
dtnew.AcceptChanges(),只能更新DataTable.GetChanges得到的dtnew;
dtnew和DataTableOrg是2个独立,不能联动。
2、如果使用遍历更新,数据多的话,感觉效率有点低了。
1、如果使用
DataTable dtnew=DataTableOrg.GetChanges(DataRowState.Deleted)
dtnew.AcceptChanges(),只能更新DataTable.GetChanges得到的dtnew;
dtnew和DataTableOrg是2个独立,不能联动。
2、如果使用遍历更新,数据多的话,感觉效率有点低了。
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 里的事务管理器
DataTable通过sql更新没有疑问,可以分开做。
用遍历的方式就是数据多时,效率差了。