Transaction and ADO.NET

  • Thread starter Francois Malgreve
  • Start date
F

Francois Malgreve

Hi,

I am using SQLTransaction.
I just wonder if it is possible to use the same transaction over multiple
command object.
I would like to have 3 commands object in my code (3 inserts or updates) and
put them in the same transactions.
Somehow in the .NET framework reference, it is using a single Command object
and changing it's CommandText property like in the following exemple.

(...)
myCommand.CommandText = "Insert into Region (RegionID, RegionDescription)
VALUES (100, 'Description')";
myCommand.ExecuteNonQuery();
myCommand.CommandText = "Insert into Region (RegionID, RegionDescription)
VALUES (101, 'Description')";
myCommand.ExecuteNonQuery();
myTrans.Commit();
(...)

This hardcoded way to do is unacceptable as my paramters values are set at
run time and not at compile time.

Any hint? or any link to some guidelines or articles about this?

thank you

francois
 
M

Miha Markic

Hi,

Yes, it is possible.
Just assign the same connection and transaction instances to
command.Connection and Transaction properties.
 
F

Francois Malgreve

thanks a lot

francois
Miha Markic said:
Hi,

Yes, it is possible.
Just assign the same connection and transaction instances to
command.Connection and Transaction properties.
 

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