I&#039;ve been asked to wrap some of my SQL code into a transaction so users can cancel it if need be. Trouble is I&#039;ve not done transaction since Uni.<BR><BR>I&#039;ve got a number of SQL Commands firing away in order, some of them needed to return the id of the record they just inserted using @@Indentity for use later, so I ran those SQL statements in a DataAdapter. <BR><BR>Heres the trouble though I&#039;ve had a look at transactions and it "seems" that they only work for SQLCommand objects not DataAdapters. Does anyone have any ideas on how I can wrap both my SQL Commands and DataAdapters in a Transaction?<BR><BR>I&#039;ve seen some code like the one below and I know that DataAdapters can accept a SQLCommand. So rather than writting in the SQL as a string for my DataAdapter (as I do now) should I first create a SQLCommand, set it to the Transaction object then pass this to the DataAdapter to use?<BR><BR>Any help greatfully received. :)<BR><BR>Pete<BR><BR>try<BR>{<BR> myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, &#039;Description&#039;)";<BR> myCommand.ExecuteNonQuery();<BR> myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, &#039;Description&#039;)";<BR> myCommand.ExecuteNonQuery();<BR> myTrans.Commit();<BR> Console.WriteLine("Both records are written to database.");<BR>}<BR>catch(Exception e)<BR>{<BR> try<BR> {<BR> myTrans.Rollback();<BR> }<BR> catch (SqlException ex)<BR> {<BR> if (myTrans.Connection != null)<BR> {<BR> Console.WriteLine("An exception of type " + ex.GetType() +<BR> " was encountered while attempting to roll back the transaction.");<BR> }<BR> }<BR><BR> Console.WriteLine("An exception of type " + e.GetType() +<BR> "was encountered while inserting the data.");<BR> Console.WriteLine("Neither record was written to database.");<BR>}<BR>finally<BR>{<BR> myConnection.Close();<BR>}<BR><BR>