Transaction for TableAdapters

D

DG

I have two SqlTableAdapters (for typed dataset, generated by VS) and want to
do update of tables.
In transaction of course.

How to do it?

i try:

SqlConnection conn = new SqlConnection(Global.ConnectionString);

DSTableAdapters.Table1Adapter ta1 = new DSTableAdapters.Table1Adapter ();
DSTableAdapters.Table2Adapter ta2 = new DSTableAdapters.Table2Adapter ();

conn.Open();
trans = conn.BeginTransaction();

ta1.Connection = conn;
ta1.Connection = conn;

ta1.Update(DS.Table1);

I get an exception:

ExecuteReader requires the command to have a transaction when the connection
assigned to the command is in a pending local transaction. The Transaction
property of the command has not been initialized.

Thank you!
 
A

AMDRIT

Try changing the order of prcedural logic

SqlConnection conn = new SqlConnection(Global.ConnectionString);

DSTableAdapters.Table1Adapter ta1 = new DSTableAdapters.Table1Adapter ();
DSTableAdapters.Table2Adapter ta2 = new DSTableAdapters.Table2Adapter ();

ta1.Connection = conn;
ta2.Connection = conn;

conn.Open();
trans = conn.BeginTransaction();

ta1.Update(DS.Table1);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top