C# 类型化数据集和多事务
我正在使用类型化数据集(.xsd)访问和更新我的数据库。 我有两个表适配器,用于更新两个不同表中的记录C# 类型化数据集和多事务,c#,.net,ado.net,C#,.net,Ado.net,我正在使用类型化数据集(.xsd)访问和更新我的数据库。 我有两个表适配器,用于更新两个不同表中的记录 我无法找到在一个事务中执行两次更新的方法。您可以使用TransactionScope: using (var ts = new TransactionScope()) { // Perform updates using different table adapters using
我无法找到在一个事务中执行两次更新的方法。您可以使用
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
类的内容