Home | Overview | How Do I | FAQ | Sample | Tutorial | ODBC 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:
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:
This approach might be suitable for simple data entry or data viewing applications.
Let AppWizard create the CDaoRecordView and CDaoRecordset 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 CDaoDatabase 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 DAOENROL.
Let AppWizard create the CDaoRecordView and a CDaoRecordset 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 ENROLL 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.
Perhaps the forms appear in separate windows or as panes in a splitter window. Let AppWizard create the first CDaoRecordView and CDaoRecordset. Then use ClassWizard to add more of each.
In AppWizard, select basic database support, without a view. A dialog-based application might be appropriate for this need.
Use ClassWizard to create a CDaoRecordset 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.
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 DAOVIEW.
For information about splitter windows, see Enhancing Views in the Scribble tutorial. For information about using multiple views in general, see Multiple Document Types, Views, and Frame Windows.
This topic discusses the MFC DAO classes with respect to support for using the MFC DAO classes:
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