Using transactions with TableAdapters

I have several table adapters, each with an InsertCommand (among others). I call BeginTransaction before I start calling Update for each adapter. Update results in the InsertCommand being used but I get an exception because the command has no transaction.

The commands are private members of the VisualStudio-generated adapter classes so I cannot access them to set their Transaction members.

Is there a "proper" way to do this?

[432 byte] By [PhilJPearson] at [2008-2-17]
# 1
You will find the answer in the code sample at - http://windowsforms.net/samples/ThreeLevelUpdate.zip

Look at Form1.vb in this sample. You will find the following code.

' start a transaction based on the ParentTableAdapter
transaction = Me.ParentTableAdapter.Connection.BeginTransaction()
' using the new transaction, establish all Adapters, including the ParentTableAdapter in the transaction
Me.ParentTableAdapter.AdapterTransaction = transaction
Me.ChildTableAdapter.AdapterTransaction = transaction
Me.GrandChildTableAdapter.AdapterTransaction = transaction

SirajLala at 2007-9-8 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified