Transaction and ADO.NET

  • Thread starter Thread starter Francois Malgreve
  • Start date 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
 
Hi,

Yes, it is possible.
Just assign the same connection and transaction instances to
command.Connection and Transaction properties.
 
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.
 
Back
Top