次の方法で共有


ClassWizard: Database Support

OverviewHow Do I

You can use ClassWizard to work with two main database classes for Open Database Connectivity (ODBC) or two main classes for Data Access Objects (DAO):

  • (for ODBC) or (for DAO)   Represents a set of records selected from a data source.

  • (for ODBC) or (for DAO)   Supplies a database form, based on a dialog resource template, whose controls map to the field data members of an associated recordset object.

Note   If you are using the MFC ODBC class CRecordset, this article applies to recordsets in which bulk row fetching has not been implemented. For information about recordsets that implement bulk row fetching, see the article Recordset: Fetching Records in Bulk (ODBC).

DDX and Foreign Object Support

When you create a record view class, you associate it with a particular -derived or -derived class and map the record view's controls to field data members of the recordset class.

This close association between a record view and a recordset takes advantage of another feature you can use in ClassWizard: "foreign objects." Dialog data exchange (DDX) lets you simplify data transfer between the controls in a dialog box or form view and the data members in a corresponding class. With foreign objects, you can exchange data between the controls and the data members of a separate object — in this case, between the controls of a record view and the data members of a recordset.

When you specify the CRecordset-derived class or CDaoRecordset-derived class to associate with a CRecordView-derived class or CDaoRecordView-derived class, you can name an existing recordset class or create a new one. ClassWizard adds a member variable to the record view class named, by default, m_pSet. The data type of this variable is the recordset class. The following figure shows the relationships between a record view on the screen, a record view object, and a recordset object. The recordset is the foreign object. ClassWizard creates the record view and recordset classes and maps record view controls to recordset data members via m_pSet.

DDX and Foreign Objects

Database Source Files

When you create a / or / class with ClassWizard, the wizard creates the classes in the files you specify in the Add Class dialog box. The default filenames are based on the class name you enter. You can modify the default names, place the recordset and record view in the same files, or consolidate all recordsets in one set of files.

Browsing and Editing Database Classes

You can also browse and edit existing classes with ClassWizard. When you edit an existing recordset class, ClassWizard provides a dialog box that you can use to update the table columns bound to the recordset if the table's schema has changed since you created the class. You can also, with a little extra work, use this mechanism to specify the columns of additional tables for a join of tables. For more information about joins in ODBC, see the article Recordset: Performing a Join (ODBC). Performing a join with DAO is similar.

The following articles explain the details of using ClassWizard's database support:

For more information about ODBC or DAO database support, see the article Databases: Overview.

See Also   ClassWizard: Creating a Recordset Class, Visual C++ Wizards that Help You Begin Your Program