Add a CRecordset Derived Class

Note: The following steps use the Student Registration database (stdreg32.mdb). Make sure that you’ve registered the database as described in Register a Database

1.  Select Class View from the View menu.

2. Right click on DbQuery and click Add, then Class.

3. Select MFC from the tree node, and MFC ODBC Consumer from the list box.

Adding a CRecordset-derived class to your project

4. Click the Data Source... button and select Student Registration under the Machine Data Source tab.

Selecting a Datasource

5. Press OK.

The Login dialog box for the selected DataSource appears.

6. Enter the Login and Password if applicable.

7. Click OK to open the Select Database Object dialog box.

8. Select the Student table and press OK.

Selecting a Table

9. Click OK.

10. Enter CStudentSet in the Class: field, StudentSet.h in the .h file: field, and StudentSet.cpp in the .cpp file: field.

11. Place a checkmark in the Bind all columns check box, and select the Dynaset radio button.

If Snapshot is selected and a Unicode build is used, recordset is read-only.

Entering Class Information

12. Click Finish to generate the necessary files.

13. The wizard may put an error message in the StudentSet.cpp file as follows:

 

#error Security Issue: The connection string may contain a password

//The connection string below may contain plain text

//passwords and/or other sensitive information. Please remove //the #error after reviewing the connection string for any

//security related issues. You may want to store the password //in some other form or use a different user authentication.

 

This error message can be removed for the purpose of this tutorial.