Wrapping many database changes in a transaction

I have a web service which uses a dataset input parameter to update the master database.  Most of update/insert code is of this variety

For each row in dataset.tables("Table1").rows
   'update or insert
For each row in dataset.tables("Table2").rows
   'update or insert
For each row in dataset.tables("Table10").rows
    'update or insert

it updates 10+ tables.  

My problem is that when we get errors with connectivity or bad data, we get it partly updated.  

What is the best way to wrap this in a transaction?  I have done them before but not to this degree.  Does wrapping all the statements in one transaction work?

Also, one of the tables has this:

For each row in dataset.tables("Table6").rows
    'update or insert

how does that affect using a transaction?

Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
If you apply the transaction to the Connection object, then committing or rolling back should apply to all changes made during that session.
gdinunzioAuthor Commented:

Apparantly using the transactionscope is the preferred way to do it now as opposed to the old transaction object.

This is my code
            Using ts As New TransactionScope
                Using cnn As New OracleConnection(connectionstring)
                    Using cmdVldtUsr As New OracleCommand("SELECT ...", cnn)
                        With cmdVldtUsr
                            .BindByName = True                           
                            rdr = .ExecuteReader
                        End With
                        'Validate User
                        If rdr.Read() Then                           
                            Using cmd As New OracleCommand()
				'Update all tables here   
                            End Using                              
                        End If
                    End Using
                End Using
                'Commit Changes
            End Using
        Catch ex As TransactionAbortedException
            ' throw("TransactionAbortedException Message: {0}", ex.Message)
        Catch ex As ApplicationException
            ' MessageBox.Show("ApplicationException Message: {0}", ex.Message)

        End Try

Open in new window

Bob LearnedCommented:
You can use the TransactionScope, but IMHO that is a much heavier operation, since it can handle crossing system boundaries, and include many different sources.  I would love to see a reason why TransactionScope would be preferred in this case, over the standard transaction.  You don't appear to be doing anything complex.  Ultimately, that is your decision.

You need to remember to rollback changes when an exception occurs, unless an implicit rollback occurs, since changes weren't committed.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gdinunzioAuthor Commented:
I took the MSDN info as gospel, but you are correct since i am only connecting to one data source, I'll test both and report back what i find.

Thanks again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.