Transaction Scope with datatable updates

I have a VB windows app using a dataset with multiple datatables and a datagridview for the UI. Okay. I have the datatable. updates and inserts and deletes working.

Now, I just want to wrap the calls to the different table updates/inserts/deletes in a single transaction so I can manage the errors and roll it all back.

Is TransactionScope an option for me?

Using .net 2.0, VB 2005, ... I tried to add the System.transaction but it doesn't seem to know it. "Imports System.Transactions" ... does not load or find it. Is this just a stupid syntax or basic know-how that I'm missing ?

I see SQLClient.SQLTransaction and I found an article that says I need to create a new transaction, ... it used OleDbTransaction = cn.BeginTransaction and set the .Transaction property of each DataAdapter's Command (UpdateCommand, InsertCommand, DeleteCommand). ... I have 3 adapters, with 3 commands that 9 statements. And it isn't clear if this goes with the DataAdapter definition/setup or when I'm ready to do the updates.

I'm confused and have spent hours just trying to find the syntax to make the transaction happen in .net 2, VB and the dataset/Datatable commands.

Can someone point me to the straight answer?

I've really need to get it done and go on to something else. Thanks.

[1337 byte] By [LoriJ] at [2008-2-27]
# 1

Update: I did get the datatable command .transaction Property option working. (Which I found via a Google search and some book, ... not on MSDN/Microsoft.) I'll include it here in case it might help someone else.

If anyone knows how to have made TransactionScope work for me, I'd be happy to learn how.

Data Table Command .Transaction Property Solution

(Assumes have dataset, with 2 datatables and their update/insert/delete commands defined elsewhere in the code.)

Private cn as New SQLClient.SQLConnection(strConn) ... cn is used in data adapter setup and update section

In Update Subroutine:

Dim SQLTranx as SqlTransaction = cn.BeginTransaction

Table1sda.UpdateCommand.Transaction = SQLTranx

Table1sda.InsertCommand.Transaction = SQLTranx

Table1sda.DeleteCommand.Transaction = SQLTranx

Table2sda.UpdateComand.Transaction = SQLTranx

Table2sda.InsertCommand.Transaction = SQLTranx

Table2sda.DeleteCommand.Transaction = SQLTranx

Try

..... do the updates for both Table2 and Table1

SQLTranx.Commit()

Catch e as DBConcurrencyException

SQLTranx.Rollback()

Give User Error Msg.

End Try

LoriJ at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Transactions Programming...
# 2

Hey Lori,

My guess is that you need to include a reference to the System.Transactions Assembly for your project. In solution explorer right click your project and select "Add Reference". Under the .NET tab select System.Transactions and click OK. You should now be able to use TransactionScope.

Let me know if that doesn't fix things,
Miguel

MiguelGasca-MSFT at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Transactions Programming...

Software Development for Windows Vista

Site Classified