RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TAdoDbxTransaction Class

Represents an instance of the TAdoDbxTransaction object.

Pascal
TAdoDbxTransaction = class(DbTransaction);
C++
class TAdoDbxTransaction : public DbTransaction;

Borland.Data.AdoDbxClientProvider

Use the BeginTransaction method in TAdoDbxConnection to create a new instance of the TAdoDbxTransaction object. You use this method within the context of a TAdoDbxConnection object. Each transaction is directly related to a specific connection. The connection must be open before calling BeginTransaction. 

TAdoDbxTransaction implements the ADO.NET class DbTransaction

TAdoDbxTransaction takes care of controlling a database transaction with respect to a connection. Calling the TAdoDbxConnection.BeginTransaction method on an opened connection returns a new TAdoDbxTransaction object. The Commit and Rollback methods take care of committing or rolling back a transaction. For setting different isolation levels, the IsolationLevel property can be used, and the default isolation is ReadCommitted . The current implementation supports nested multiple transactions on a single connection, but not overlapped multiple transactions on a single connection.  

The following c# code shows runtime parameter binding and execution of a stored procedure in the context of a transaction.

static void BindParameter ( TAdoDbxConnection Conn, Int32 Times )
 {
     Int32 Count = 0, Rows = 0;
     TAdoDbxTransaction Trans = (TAdoDbxTransaction) Conn.BeginTransaction();
      
     TAdoDbxCommand Comm = (TAdoDbxCommand) Conn.CreateCommand();
     Comm.Connection   = Conn;
     Comm.Transaction  = Trans;

     Comm.CommandType = CommandType.StoredProcedure; 
     Comm.CommandText  = "MYTESTPROC";

     Comm.Prepare();

     TAdoDbxParameter param1 = Comm.Parameters.Add("P1", 
       DbType.StringFixedLength, 10);
     TAdoDbxParameter param2 = Comm.Parameters.Add("P2", 
       DbType.String, 5);
     param2.Direction = ParameterDirection.InputOutput;
     param2.Precision = 25;
     TAdoDbxParameter param3 = Comm.Parameters.Add("P3",
       DbType.Decimal);
     param3.Direction = ParameterDirection.Output;
          
     
     while ( Count < Times )
    {
        param1.Value = "Record" + Count;
        param2.Value = "Hello";
        param3.Value = null;

        Rows = Comm.ExecuteNonQuery();
        Console.WriteLine("Output param from  MYTESTPROC=  " + param2.Value );
        Console.WriteLine("InputOutput param from  MYTESTPROC=  " + param3.Value );
        Count ++;

     }

     Comm.Close();

     Trans.Commit();
  }

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!