Home | Overview | How Do I | Tutorial
The Microsoft Foundation Class Library database classes supply class CRecordView (for ODBC) and class CDaoRecordView (for DAO) for implementing database forms with controls in which to display record fields. This article explains how to create a record view class with ClassWizard and associate it with a recordset class.
Important To use the MFC database classes, you must have specified at least minimum database support ("Only include header files") in AppWizard. If you didn't, open file Stdafx.h and add an #include directive for Afxdb.h (if you're using the MFC ODBC classes) or Afxdao.h (if you're using the MFC DAO classes).
The purpose of a record view class is to provide a form view whose controls are mapped directly to the field data members of a recordset object (and indirectly to the corresponding columns in a table on the data source). Setting up this mapping enables dialog data exchange (DDX) directly between the form's controls and the recordset's field data members. This article explains how to make the association.
Tip The easiest way to use a record view as your application's main view is to do so when you initially run AppWizard. See Database Options in AppWizard.
The following procedure begins the process.
To create a record view associated with a recordset
See the article ClassWizard: Creating a Recordset Class.
See Using the Dialog Editor to Add Controls or Dialog Editor Topics for Visual C++ for more information.
In the Styles and More Styles property pages of your dialog template, set the following properties, as you would for a CFormView object:
Tip As you place controls on your dialog template, you can help ClassWizard be smarter. See the tips in the article ClassWizard: Mapping Form Controls to Recordset Fields.
To continue from step 2, see the following procedure.
To create the record view class
-or-
Click New to create a new recordset class. In this case, select a data source and table for the recordset as prompted. Close the Select a Recordset dialog box. On returning to the Member Variables tab, select your new recordset class.
Note If you next click the Class Info tab, you'll see your recordset class listed in the Foreign Class box. For more information about "foreign" classes, see the article ClassWizard: Foreign Objects.
For information about binding your record view controls to the recordset, see the article ClassWizard: Mapping Form Controls to Recordset Fields.
See Also ClassWizard: Database Support, ClassWizard: Creating a Recordset Class, ClassWizard: Binding Recordset Fields to Table Columns