ClassWizard: Creating a Recordset Class
Home | Overview | How Do I | Tutorial
This article explains how to create a recordset class with ClassWizard.
You'll need a new CRecordset-derived class (for ODBC) or CDaoRecordset-derived class (for DAO) for each table, join of tables, or predefined query you work with in your program. Each recordset class specifies its own set of columns and may also specify parameters. For information about the structure of your recordset class and its uses, see the article Recordset: Architecture (ODBC) or DAO Recordset: Architecture.
For information about mapping recordset field data members to columns in the table, see the article ClassWizard: Binding Recordset Fields to Table Columns.
For information about using a CRecordset (ODBC) for a join of tables, see the article Recordset: Performing a Join (ODBC). (Performing a join with DAO is similar.)
For information about using a CRecordset for a predefined query, see the article Recordset: Declaring a Class for a Predefined Query (ODBC). For information about predefined ("saved") queries in DAO, see the article DAO Querydef.
Note When creating CRecordset-derived or CDaoRecordset-derived classes with ClassWizard, be careful when selecting multiple tables or queries. Selecting multiple tables or queries will result in the construction of a JOIN query without any restriction on how to perform the JOIN (called a cross product or a Cartesian product JOIN). You may wish to specify a filter using CRecordset::m_strFilter or CDaoRecordset::m_strFilter (resulting in MFC building an SQL WHERE clause) before the recordset is opened. This will constrain the number of records in the result set. This is especially necessary when using the ODBC Cursor Library, since the Cursor Library may create a large temporary file for result sets with many records.
The table below shows the major steps in creating a recordset class.
Recordset Class Creation Summary
To Do this
Create the class Use the Add Class dialog box in ClassWizard.
Select a data source and database table for the class Select options in the Database Options dialog box. These include a data source, possibly a recordset type, and possibly some advanced options. Then specify details about the data source in the Select Database dialog box (for ODBC) or the Open dialog box (for DAO). Next, use the Select Database Tables dialog box to select tables from those available on the data source.
Remove any column mappings you don't want. By default, AppWizard and ClassWizard bind all columns in the table to recordset field data members Select a column name on the Member Variables tab and choose Delete Variable.
Optionally parameterize the underlying SQL statements Manually add parameter data members, or, in DAO, base your recordset on a parameterized a querydef object.
Optionally use dialog data exchange (DDX) to map recordset data members to controls in a record view See the article Record Views.
For more information about parameterizing your class, see the article Recordset: Parameterizing a Recordset (ODBC) or the article DAO Queries: Filtering and Parameterizing Queries. For information about using DDX between record view controls and recordset data members, see the article ClassWizard: Mapping Form Controls to Recordset Fields.
Partager