1
我有一个WinForm应用程序使用typed-dataset tabledapters查询SqlCe数据库。我有一个主窗体程序集和一个处理每个数据库操作的数据库程序集。我遇到了在事务中使用tableadapter更新的问题,我很感激任何人都可以给我任何想法。使用类型化数据集的TransactionScope
Update()方法给出了这样的错误:
"The connection object can not be enlisted in transaction scope."
这里是我的代码:
namespace Main
{
public class MainForm
{
private MyDbAssembly.MyDbClass db;
//instantiate and db fill methods omitted..
private void DeleteStuff()
{
using (TransactionScope trans = new TransactionScope())
{
this.db.Delete(id);
UpdateDb();
trans.Complete();
}
}
private void UpdateDb()
{
//bindingsource endedit & datagridview endedit methods omitted..
this.db.Update();
}
}
}
namespace MyDbAssembly
{
public class MyDbClass
{
private myTypedDataset myDataSet;
private myTypedDataSetTableAdapter.MyTable1Adapter table1Adapter;
//instantiate methods omitted..
public void Delete(Guid id)
{
this.myDataSet.MyTable1.FindByID(id).Delete();
}
public void Update()
{
this.table1Adapter.Update(myDataSet.MyTable); //<-- ERROR LINE
}
}
}
你不是问过这个吗? http://stackoverflow.com/questions/602421 – 2009-06-26 22:20:22