Using (sqlconnection connection = new sqlconnection (sqlhelper. connectionstringlocaltransaction ))
{
Connection. open ();
Sqlcommand command = connection. createcommand ();
Sqltransaction transaction;
Transaction = connection. begintransaction ("sampletransaction ");
Command. Connection = connection;
Command. Transaction = transaction;
Try
{
Command. commandtext = "insert into region (regionid, regiondescription) values (100, ''description')"; command. executenonquery ();
Command. commandtext = "insert into region (regionid, regiondescription) values (101, ''description')"; command. executenonquery (); // attempt to commit the transaction.
Transaction. Commit ();
}
Catch (exception ex)
{
Try
{
Transaction. rollback ();
}
Catch (exception ex2)
{
// Console. writeline ("rollback exception type: {0}", ex2.gettype ());
// Console. writeline ("message: {0}", ex2.message );
}
}
}