共用方式為


DAO: Creating, Opening, and Closing DAO Objects

OverviewHow Do IFAQSampleODBC Driver List

This family of articles explains what it means to “open” or “create” an MFC DAO object and what it means to “close” the object when you finish with it.

This article discusses how MFC objects are constructed and points to related general articles. The following additional articles discuss the Create, Open, and Close actions:

Two-Stage Construction of MFC DAO Objects

As with most MFC objects, you use a two-stage process to create the MFC object and put it into an open state.

Creating a New Object

To create a new MFC DAO object

  1. Construct the object (on the stack or on the heap, using the new operator).

  2. Call the object’s Create member function.

  3. In some cases, call the Append member function to add the object to the appropriate DAO collection.

    • Database objects are appended to the collection automatically upon creation. CDaoDatabase has no Append member function.

    • Workspace and querydef objects can be created as temporary objects. To learn how to create a temporary object, see its class overview. Temporary objects are not appended.

    • Objects that you want to persist between database engine sessions should be appended.

For details, see each class constructor in the Class Library Reference.

Opening an Existing Object

To construct and open an MFC DAO Object

  1. Construct the object (on the stack or on the heap, using the new operator).

  2. Call the object's Open member function.

Before you call Open, the object is typically uninitialized and unusable (for exceptions, see ). This example shows how to construct and open a object:

// CDelinquentSet is derived from CDaoRecordset
// Construct the recordset using the default database
CDelinquentSet rsDelinquentAccts;

// Set the object's properties as needed, then...
rsDelinquentAccts.Open( );  // Using default parameters

For related information, see the following articles:

See Also   , , , , , , , , , , , , ,