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
From the View menu, click ClassWizard.
Click Add Class and, from the menu, select New.
This opens the New Class dialog box.
Under Class Information, in the Name box, type
CCourseSet
.From the Base Class list, select CDaoRecordset.
Click Change and shorten the filenames to CourseSe.h and CourseSe.cpp. Click OK.
Click OK.
This opens the Database Options dialog box.
To connect the recordset class to the Course table
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.
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.
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 showsCCourseSet
, and three names are listed in the Column Names box. The table below shows the column names, their data members, and their data types.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 |
|
CourseTitle | CString |
|
Hours | short |
|