RAD Studio |  |

Retrieving Result Sets with Commands
See Also
Collapse All

Unlike TADOQuery components, which use different methods to execute depending on whether they return a result set, TADOCommand always uses the Execute command to execute the command, regardless of whether it returns a result set. When the command returns a result set, Execute returns an interface to the ADO _RecordSet interface.

The most convenient way to work with this interface is to assign it to the RecordSet property of an ADO dataset.

For example, the following code uses TADOCommand (ADOCommand1) to execute a SELECT query, which returns a result set. This result set is then assigned to the RecordSet property of a TADODataSet component (ADODataSet1).

Copy Code

    with ADOCommand1 do begin
      CommandText := 'SELECT Company, State ' +
        'FROM customer ' +
        'WHERE State = :StateParam';
      CommandType := cmdText;
      Parameters.ParamByName('StateParam').Value := 'HI';
      ADODataSet1.Recordset := Execute;
    end;

Copy Code

    ADOCommand1->CommandText = "SELECT Company, State ";
    ADOCommand1->CommandText += "FROM customer ";
    ADOCommand1->CommandText += "WHERE State = :StateParam";
    ADOCommand1->CommandType = cmdText;
    ADOCommand1->Parameters->ParamByName("StateParam")->Value = "HI";
    ADOCommand1->Recordset = ADOCommand1->Execute();

As soon as the result set is assigned to the ADO dataset's Recordset property, the dataset is automatically activated and the data is available.

See Also

Specifying the Command

Using the Execute Method

Canceling Commands

Handling Command Parameters

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!