RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TAdoDbxCommand.Transaction Property

Provides the transaction in which the TAdoDbxCommand executes.

Pascal
property Transaction: DbTransaction;
C++
__property DbTransaction Transaction;

Transaction provides the transaction the command executes within. The transaction must already have been created prior to naming it with the Transaction property on the TAdoDbxCommand.

Warning: You cannot set the Transaction property if it is already set to a specific value and the command is in the process of executing. If you set the transaction property to a TAdoDbxTransaction object that is not connected to the same TAdoDbxConnection as the TAdoDbxCommand object, an exception is thrown the next time you attempt to execute a statement.

connection.Open();
TAdoDbxTransaction transaction = connection.BeginTransaction();
string textSQL = "INSERT INTO Employee (...) VALUES (...)";
TAdoDbxCommand command = new TAdoDbxCommand(textSQL, connection, transaction);
int intRecordsAffected = command.ExecuteNonQuery();
if (intRecordsAffected == 1)
{
    MessageBox.Show("Row updated.");
    transaction.Commit();
}
else
{
    // No records affected
    MessageBox.Show("No row updated.");
    transaction.Rollback();
}

 

connection.Open();
TTrans: TTransaction.BeginTransaction(connection);
string textSQL = "INSERT INTO Employee (...) VALUES (...)";
TAdoDbxCommand command = new TAdoDbxCommand(textSQL, connection, TTrans);
int intRecordsAffected = command.ExecuteNonQuery();
if (intRecordsAffected == 1)
{
    MessageBox.Show("Row updated.");
    TTrans.Commit();
}
else
{
    // No records affected
    MessageBox("No row updated.", [smbOK]);
    TTrans.Rollback();
}

 

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