Fetching Multiple Result Sets

From RAD Studio
Jump to: navigation, search

Go Up to Executing Stored Procedures That Don't Return a Result Set


Some stored procedures return multiple sets of records. The dataset only fetches the first set when you open it. If you are using TSQLStoredProc or TADOStoredProc, you can access the other sets of records by calling the NextRecordSet method:

var
  DataSet2: TCustomSQLDataSet;
begin
  DataSet2 := SQLStoredProc1.NextRecordSet;
  ...
TCustomSQLDataSet *DataSet2 = SQLStoredProc1->NextRecordSet();

In TSQLStoredProc, NextRecordSet returns a newly created TCustomSQLDataSet component that provides access to the next set of records. In TADOStoredProc, NextRecordset returns an interface that can be assigned to the RecordSet property of an existing ADO dataset. For either class, the method returns the number of records in the returned dataset as an output parameter.

The first time you call NextRecordSet, it returns the second set of records. Calling NextRecordSet again returns a third dataset, and so on, until there are no more sets of records. When there are no additional cursors, NextRecordSet returns nil.

See Also