我使用Typed Dataset(.xsd)来访问和更新我的数据库。 我有两个表适配器用于更新两个不同表中的记录。
我无法找到在单笔交易中执行两次更新的方法。
答案 0 :(得分:2)
您可以使用TransactionScope
:
using (var ts = new TransactionScope())
{
// Perform updates using different table adapters
using (var ta1 = new tbl1TableAdapter())
using (var ta2 = new tbl2TableAdapter())
{
ta1.Update(yourDataSet.tbl1);
ta2.Update(yourDataSet.tbl2);
}
ts.Complete();
yourDataSet.AcceptChanges();
}
您可以阅读TransactionScope
课程here