HOWTO: Retrieving Multiple Resultsets with Varying Columns (183297)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
This article was previously published under Q183297 SUMMARY
Using the Microsoft Foundation Class (MFC) Open Database Connectivity
(ODBC) database classes, you can call a stored procedure that can return
multiple resultsets with a varying number of columns. However, some
additional work is required.
To retrieve multiple resultsets with a varying number of columns and types,
you should use the CRecordset class directly with the GetFieldValue()
method. Derived CRecordset classes using RFX functions are not designed to
bind to multiple resultsets with a differing number of columns and types,
although it may be possible to place conditionals in the DoFieldExchange()
function to call different RFX functions for different results.
Why is the additional work required? Consider a stored procedure returning
two resultsets; one with one column and the other with two columns. If a
Visual C++ MFC ODBC application executes this stored procedure and captures
the results, the second resultset returns only one column; in other words,
it returns only as many columns as the first resultset returned.
This occurs because the field cache information created by the MFC database
classes is not refreshed inside FlushResultSet(). Therefore, the resultset
is retrieved with the existing cache information, which was built in
AllocAndCacheInfo() in CRecordset::Open(). To properly retrieve the second
resultset, call CRecordset::AllocAndCacheFieldInfo() after FlushResultSet()
and before MoveNext().
Because CRecordset::AllocAndCacheFieldInfo() is a protected member
function, create a new function that does the same thing as
AllocAndCacheFieldInfo() from the Dbcore.cpp MFC sources.
Modification Type: | Major | Last Reviewed: | 7/17/2001 |
---|
Keywords: | kbcode kbDatabase kbhowto KB183297 |
---|
|