Creating a New DAO Database Application

When you use AppWizard to create a DAO database application, the only database type offered as a selection is the Microsoft Access .MDB database. Using either Access data in an .MDB file or an installable ISAM database as an attached table to an .MDB file gives your application the best performance for data retrieval and manipulation. The procedures in this tutorial assume that you are using the StdReg32.mdb file supplied on the Visual C++ distribution CD.

Suggested Reading

AppWizard lets you specify whether your database application uses a file as well as a database. The DaoEnrol application does not need a file, so it is based on the Database view without file support option in AppWizard.

Note   The following procedure describes how to enter the correct values in the AppWizard Steps to create the DaoEnrol application. Many of the Steps contain choices that you will not use to create the starter files for DaoEnrol.

To create the tutorial database application

  1. From the File menu, click New.

    The New dialog box appears.

  2. Click the Projects tab.

  3. Fill in or select the remaining boxes as follows:
    • In the Type box, select MFC AppWizard (exe).

    • In the Project Name box, type DAOEnrol.

      In the Location box, type the name of the directory in which you want your project files stored. AppWizard creates this directory if it doesn't exist.

  4. Click OK.

    AppWizard creates the project directory, and the MFC AppWizard – Step 1 dialog box appears.

  5. Click the Single document radio button, and then click Next.

  6. In the MFC AppWizard – Step 2 of 6 dialog box:
    • Click Database view without file support.

      When you create a database application without file support, AppWizard always creates it as an SDI application.

      This enables the Data Source button.

    • Click Data Source.

      The Database Options dialog box appears.

    • Click DAO and, from the drop-down list box, navigate to and select the Microsoft Access file StdReg32.mdb, then click OK.

    • AppWizard uses Dynaset as the default recordset type. The check box Detect dirty columns is checked by default. Click OK. The Select Database Tables dialog box appears.

    • Select the table name Section, and click OK to return to the MFC AppWizard – Step 2 of 6 dialog box.
  7. Click Next to proceed to the rest of the AppWizard Steps.

  8. Click Next in AppWizard for Steps 3, 4, and 5 to accept the default options.

    In the MFC AppWizard – Step 6 of 6 dialog box, you can check and, if necessary, modify the default names that AppWizard creates for your program’s classes and files.

    Note   By default, AppWizard bases the names of classes on the project name you supply. This naming is probably fine if your application has only one recordset/record view pair. If your application has multiple recordsets and record views, it’s a good idea to change the name of the first recordset/record view pair created by AppWizard so the naming better reflects the name of the table in the data source. For DaoEnrol, you’ll modify two class names and their related header and implementation filenames, even though the tutorial uses only one recordset/record view pair.

  9. In MFC AppWizard – Step 6 of 6, make the following changes to class names:
    • Select the class CDaoEnrolDoc, and change it as follows:

      In the Header file box, change the header filename to DenrlDoc.h.

      In the Implementation file box, change the name to DenrlDoc.cpp.

    • Select the class CDaoEnrolView, and change it as follows:

      In the Class name box, change its name to CSectionForm.

      In the Header file box, change the header filename to SectForm.h.

      In the Implementation file box, change the name to SectForm.cpp.

      The base class is CDaoRecordView.

    • Select the class CDaoEnrolSet, and change it as follows

      In the Class name box, change its name to CSectionSet.

      In the Header file box, change the header filename to SectSet.h.

      In the Implementation file box, change the name to SectSet.cpp.

      The base class is CDaoRecordset. The edit item is disabled to show that you can’t change it.

  10. Click Finish.

    The New Project Information dialog box appears, summarizing the settings and features AppWizard will generate for you when it creates your project.

    You might want to take a moment to examine the application type, classes, and features that AppWizard automatically provides.

  11. Click OK in the New Project Information dialog box.

    AppWizard creates all necessary files and opens the project.

Use ClassView to view the classes that AppWizard just created.