Requerying the CSectionSet Recordset

Whenever the user selects a new course name from the combo box, Enroll must “requery” the CSectionSet recordset to refresh its records. By selecting a new course name, the user will see records only for the class sections of that course name. The existing CSectionSet recordset contains records for the previous course name. Requerying the recordset brings it up to date for the new course name, using the current values of the filter and sort strings.

When the user accepts a selection in the combo box, the CSectionForm record view gets a CBN_SELENDOK notification message. The record view uses its handler for this message to reselect records based on the course name selected, passing the course ID as a parameter.

The following procedure describes how to use WizardBar to create this handler.

To requery the CSectionSet recordset

  1. From the Window menu, select SectionForm.cpp.

  2. From the WizardBar Filter combo box, select IDC_COURSELIST.

  3. In the Members combo box, select CBN_SELENDOK.

  4. The New Windows Message and Event Handlers dialog box opens.

  5. Click Add Handler.

  6. Click OK to accept the default name OnSelendokCourselist.

  7. Click Edit Existing to jump to the code created for the handler.

  8. In the editor window, add the following code in place of the //TODO comment:
    if (!m_pSet->IsOpen() )
    return;
    m_ctlCourseList.GetLBText(m_ctlCourseList.GetCurSel(),
    m_pSet->m_strCourseIDParam);
    m_pSet->Requery();
    if (m_pSet->IsEOF())
    {
    m_pSet->SetFieldNull(&(m_pSet->m_CourseID), FALSE);
    m_pSet->m_CourseID = m_pSet->m_strCourseIDParam;  
    }
    UpdateData(FALSE);
    
  9. Save your work.

This code requeries records from the database into the recordset, based on the parameter value in m_strCourseIDParam. The parameter value is set to the currently selected course name from the Course List combo box before requerying the database.

If you requery and it turns out that the selected course name has no class sections, the recordset is initialized with Null database field values except for CourseID. (In database terminology, Null means "having no value" and is not the same as NULL in C++.)

If you are working through the DaoEnrol tutorial, at this point you are ready to compile and run the application. After you have examined the working application, return to DaoEnrol Step 3.