Creating a New Database Application

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

Suggested Reading in the Visual C++ Programmer’s Guide

Note   In order to successfully complete the following procedure, you must have completed the steps required to register the Student Registration database with ODBC. If you have not done so, see Setting Up the Student Registration Data Source, in Lesson 1 of Enroll.

To create the tutorial database application

  1. From the File menu, choose New.

    The New dialog box appears.

  2. Click the Projects tab.

  3. Complete the Projects dialog box as follows:

    • In the Type box, select MFC AppWizard (exe).

    • In the Project Name box, type Enroll.

    • In the Location box, type the name of the directory to keep your source file project directory.

      AppWizard creates a project directory with the project's name (Enroll) under the directory specified in the Location box.

  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 ODBC and, from the drop-down list box, select Student Registration. Click OK.

      The Select Database Tables dialog box appears.

    • Select the table name Section, and click OK.

      This returns you to the MFC AppWizard – Step 2 of 6 dialog box.

      Depending on the data source type you are using, additional qualifiers may precede or follow the table name.

  7. Click Next to accept the options you have specified, then click Next in the AppWizard dialog boxes 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/view pair. If your application has multiple recordsets and record views, it’s a good idea to change the name of the first recordset/view pair created by AppWizard so the naming better reflects the name of the table in the data source. For Enroll, you’ll modify two class names and their related header and implementation filenames, even though the tutorial uses only one recordset/view pair.

  8. In the MFC AppWizard – Step 6 of 6 dialog box, make the following changes to class names:

    • Select the class CEnrollSet, 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 SectionSet.h.

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

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

    • Select the class CEnrollView,  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 SectionForm.h.

      In the Implementation file box, change the implementation filename to SectionForm.cpp.

      The base class is CRecordView.

  9. Click Finish.

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

    Take a moment to examine the application type, classes, and features that AppWizard automatically provides.

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

    AppWizard creates all necessary files and opens the project. The next topics describe the AppWizard-createf files in more detail.