DBFETCH: Demonstrates Bulk Row Fetching in the MFC ODBC Database Classes

Click to open or copy the DBFETCH project files.

The DBFETCH sample shows how to use some of the new functionality that has been added to the MFC ODBC database classes. The CRecordset object now includes support for fetching records in bulk (retrieving more than one record at a time). The DBFETCH sample lets you randomly browse data using bulk row retrieval in a fashion similar to DAOVIEW or CATALOG2.

While CRecordset does not support updating a multirow row set, you can update a multirow set directly using the ODBC SQLSetPos API. DBFETCH extends the bulk row fetching code to include support for updating data, although updating is not supported through the sample's user interface. See the RowsetEdit, RowsetAdd, and RowsetDelete members of the CBulkRecordset class. These members are really just wrappers of the ODBC SQLSetPos API.

In addition to the helpers for updating, DBFETCH also includes helpers for handling multiple errors from ODBC. Currently the CDBException object handles multiple ODBC errors by appending all the SQL state and error string information into one string. This string can be unwieldy when using multirow fetching because multiple ODBC errors are more likely to occur.

Running the Sample

To run the sample, you should have an ODBC data source already defined. Once you have one or more ODBC data source names (DSNs) set up, you can build and run the sample yourself, or simply run the sample directly from the CD. You will be prompted by the standard ODBC Connect dialog box to select a data source. The sample displays a dialog from which you choose a data source, choose a table from the data source, and choose to get the data. The data is fetched and displayed in a second dialog. You can scroll through the records, selecting the first, last, next, and previous 25 records at a time.