The following example initializes an SqlConnection, opens it, begins a transaction, rollsback the transaction, then closes the connection. To accomplish this, the method is passed an SQL connection string to use to connect to the data source.
NOTE: This example shows how to use one of the overloaded versions of RollbackTransaction. For other examples that may be available, see the individual overload topics.
void RunSqlTransaction ( string strConn ) {
SqlConnection myConn = new SqlConnection ( strConn );
myConn.Open ( );
myConn.BeginTransaction ( "SampleTransaction" );
myConn.RollbackTransaction ( "SampleTransaction" );
myConn.Close ( );
}
SqlConnection Members