asp.net.ph

OleDbConnection.BeginTransaction Method ( )

System.Data.OleDbClient Namespace   OleDbConnection Class


Begins a database transaction.

[ VB ]
Overloads Overrides Public Function BeginTransaction ( ) As OleDbTransaction

[ C# ]
public override OleDbTransaction BeginTransaction ( );

[ C++ ]
public: OleDbTransaction BeginTransaction ( );

[ JScript ]
public override function BeginTransaction ( ) : OleDbTransaction

Return Value

An object representing the new transaction.

Exceptions


Exception Type Condition
InvalidOperationException Occurs when Parallel transactions are not supported.

Remarks

You must explicity commit or roll back the transaction using the Commit or Rollback method. To ensure that the OLE DB .NET Data Provider transaction management model performs correctly, avoid using other transaction management models, such as those provided by the data source.

Example

The following example initializes an OleDbConnection, opens it, begins a transaction, commits the transaction, then closes the connection.

void RunOleDbTransaction ( string connString ) {
   OleDbConnection myConn = new OleDbConnection ( connString );
   myConn.Open ( );

   OleDbCommand myCommand = new OleDbCommand ( );
   OleDbTransaction myTrans;

   // start a local transaction
   myTrans = myConn.BeginTransaction ( );
   // assign transaction object for a pending local transaction
   myCommand.Transaction = myTrans;

   try {
      myCommand.CommandText = "Insert into Region (
         RegionID, RegionDescription ) VALUES ( 100, 'Description' ) ";
      myCommand.ExecuteNonQuery ( );

      myTrans.Commit ( );
      Response.Write ( "One record written to database." );
   } catch ( Exception e ) {
      myTrans.Rollback ( );
      Response.Write ( e.ToString ( ) );
      Response.Write ( "No record written to database." );
   } finally {
      myConn.Close ( );
   }
}
  C# VB

See Also

OleDbConnection Members   OleDbConnection.BeginTransaction Overload List   Commit   Save   Rollback Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph