次の方法で共有


DAO: Database Application Design Options

OverviewHow Do IFAQSampleODBC Driver List

This article continues the discussion begun in the article DAO: Writing a Database Application. The article DAO: Steps in Writing MFC DAO Applications completes the discussion. Those articles discuss the decisions you need to make before you run AppWizard and the steps involved in creating your starter application.

Topics covered include:

  • Application design examples

  • DAO in DLLs, multithreaded applications, and ActiveX controls

Application Design Examples

This article gives examples to suggest some of the ways you might organize your application. Sample applications mentioned in the list are available under Visual C++ Programmer’s Guide/Samples in the documentation.

Examples:

  • An application that uses a single form to view one record at a time.

    This approach might be suitable for simple data entry or data viewing applications.

    Let AppWizard create the and classes for you. Then design the form in the Visual C++ dialog editor.

    In this scenario, a single CDaoRecordset object persists for a session, and it uses an implicitly created object. The recordset, a data member of the CDaoRecordView class called m_pSet, contains all records in a table or all records returned by a query. The view lets the user scroll through the records one at a time.

    For an example, see Step 1 of the MFC Database sample .

  • A similar single-form application that displays one record at a time but also uses a second recordset to fill a list box or combo box.

    Let AppWizard create the and a to control which record is currently displayed in the form's general controls.

    Use ClassWizard to create a second CDaoRecordset based on the table or query that fills the list or combo box.

    For a view of how this works, see the MFC Database sample for the MFC ODBC classes. You’ll have to translate some of the code, but the model is the same in DAO, and most of the code is very similar as well.

    Create additional recordsets to fill more list or combo boxes as needed.

  • An application based on multiple forms.

    Perhaps the forms appear in separate windows or as panes in a splitter window. Let AppWizard create the first and . Then use ClassWizard to add more of each.

  • A bulk data processing application, where no view is required.

    In AppWizard, select basic database support, without a view. A dialog-based application might be appropriate for this need.

    Use ClassWizard to create a class for each end of the migration. Then write code to use one recordset for input and the other for output. Perform any necessary data manipulation between the two recordsets. Note that you can use the MFC DAO classes in console applications. For more information, see DAO in DLLs, Multithreaded Applications, and ActiveX Controls.

  • An application that displays multiple records at a time, perhaps in a or a .

    Use AppWizard to specify the view class on which to base your application-specific view. You can also use multiple views, perhaps displayed as panes of a splitter window.

    For an example, see the MFC Database sample .

For information about splitter windows, see in the Scribble tutorial. For information about using multiple views in general, see Multiple Document Types, Views, and Frame Windows.

DAO in DLLs, Multithreaded Applications, and ActiveX Controls

This topic discusses the MFC DAO classes with respect to support for using the MFC DAO classes:

  • In dynamic link libraries (DLLs)

  • In ActiveX controls

  • In multithreaded applications

  • In console applications

  • In applications built for Unicode or double-byte character systems (DBCS)

You can use the MFC DAO classes in any DLL, as well as in ActiveX controls. For more information about using the MFC DAO classes in a DLL, see the article DAO: Using DAO in DLLs.

DAO itself is not multithreaded, so you can’t use the MFC DAO classes in multiple threads. Confine your DAO code to a single thread of execution.

Depending on what MFC functionality you call, you should be able to use the MFC DAO classes in console applications as well. Make sure the application uses no graphical user-interface elements. For example, if you’re using an ODBC data source and you supply incomplete connection information, ODBC attempts to display a dialog box for the missing information. Avoid this situation in your console applications.

The MFC DAO classes are fully enabled for Unicode and DBCS.

See Also   DAO: Where Is..., DAO: Database Tasks, DAO: Writing a Database Application, DAO: Steps in Writing MFC DAO Applications, MFC: Using Database Classes with Documents and Views, MFC: Using Database Classes Without Documents and Views