Share via


Creating a Recordset for the Course Table in DaoEnrol

Note   Before starting this topic, you should have already completed the following instructions in the Enroll tutorial, Lesson 3:

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

DaoEnrol already has one recordset, for the Section table, which fills the controls on the CSectionForm record view with information about a single class section of the currently selected course name. Now you’ll add a second recordset, for the Course table, used to fill the combo box control with a list of all available course names.

To create a new recordset class

  1. From the View menu, click ClassWizard.

  2. Click Add Class and, from the menu, select New.

    This opens the New Class dialog box.

  3. Under Class Information, in the Name box, type CCourseSet.

  4. From the Base Class list, select CDaoRecordset.

  5. Click Change and shorten the filenames to CourseSe.h and CourseSe.cpp. Click OK.

  6. Click OK.

    This opens the Database Options dialog box.

To connect the recordset class to the Course table

  1. In the Datasource area, click the DAO radio button to activate the list. Click the browse button [...] next to the DAO list.

    This displays the Open dialog box.

  2. Navigate to the StdReg32.mdb file and select it. Click OK to return to the Database Options dialog box, then click OK again.

    The Select Database Tables dialog box opens.

  3. Select the table name “Course,” and click OK.

    This connects the table name to class CCourseSet and returns you to the ClassWizard Member Variables tab. The Class name box shows CCourseSet, and three names are listed in the Column Names box. The table below shows the column names, their data members, and their data types.

  4. Click OK to close ClassWizard.

Note   On the Member Variables tab, you can see that all of the table’s columns are already assigned to field member variables. You can use ClassWizard to delete those variables if you don’t need to access or modify the columns — but be careful not to delete a field member variable for a column that is part of the table’s primary key.

CCourseSet Data Members

Column name Type Data member
CourseID CString
m_CourseID
CourseTitle CString
m_CourseTitle
Hours short
m_Hours