how would transaction work with this.

  • Thread starter Thread starter Maersa
  • Start date Start date
M

Maersa

Hi All,

I'm using the SqlCommandBuilder which automatically generates all the sql
commands, but how do I set the Transaction for it in case it fails...

SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand( "SELECT * FROM QueryInfo",
connection );
SqlCommandBuilder builder = new SqlCommandBuilder( adapter );
....

adapter.Update( dataSet );

Where would the Transaction come in play ?

thanks,
 
Each operation in SQL Server gets its own transaction by default. The
CommandBuilder commands are simply single Update commands and are bound in
their own transaction by default.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Maersa said:
Hi All,

I'm using the SqlCommandBuilder which automatically generates all the sql
commands, but how do I set the Transaction for it in case it fails...

SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand( "SELECT * FROM QueryInfo",
connection );
SqlCommandBuilder builder = new SqlCommandBuilder( adapter );
...

adapter.Update( dataSet );

Where would the Transaction come in play ?

thanks,

You can always ask the SqlCommandBuilder to generate the commands
before-hand with SqlCommandBuilder.GetInsertCommand,
SqlCommandBuilder.GetUpdateCommand and SqlCommandBuilder.GetDeleteCommand.
Then you can explicitly assign the commands to the DataAdapter and enlist
them in a transaction.

David
 
Back
Top