How Do I Use Multiple Result Sets from One Stored Procedure?
Most stored procedures return multiple result sets. Such a stored procedure usually includes one or more select statements. The consumer needs to take this into account to handle all of the result sets.
To handle multiple result sets:
-
Create a CCommand class with CMultipleResults as a template argument and with the accessor of your choice. Usually, this will be a dynamic or manual accessor. If you use another type of accessor, you may not be able to determine the output columns for each rowset.
-
Execute the stored procedure as usual and bind the columns (see How do I fetch data?).
-
Use the data.
-
Call GetNextResult on the CCommand class. If another result rowset is available, GetNextResult returns S_OK and you should rebind your columns if you are using a manual accessor. If GetNextResult returns an error, there are no further result sets available.