PRB: CRecordset Does Not Skip Deleted Records (156977)



The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), when used with:
    • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
    • Microsoft Visual C++, 32-bit Professional Edition 4.2
    • Microsoft Visual C++, 32-bit Enterprise Edition 4.2b
    • Microsoft Visual C++, 32-bit Professional Edition 4.2b
    • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
    • Microsoft Visual C++, 32-bit Professional Edition 5.0
    • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
    • Microsoft Visual C++, 32-bit Professional Edition 6.0
    • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q156977

SYMPTOMS

You may continue to see deleted records when using the CRecordset and CRecordView classes with a snapshot recordset.

CAUSE

The default behavior of the MFC ODBC classes has changed. It is now possible to move onto a record that has been deleted. If the current record has been deleted, the CRecordset IsDeleted() function will return TRUE.

RESOLUTION

Open your CRecordset using the skipDeletedRecords option, or check IsDeleted() to ensure that the current record is valid before using it.

STATUS

This behavior is by design.

MORE INFORMATION

The default behavior of a snapshot no longer skips deleted records. CRecordView opens a CRecordset with the default behavior so the CRecordView will display deleted records. An example of this behavior appears in the Enroll tutorial. If you delete the last record in the CSectionSet recordset, the deleted record will continue to be displayed in the CSectionForm record view. If you try to delete this record again, you will receive the following error message:
Operation failed, no current record

Sample Code

   // The following code shows how to override the CRecordset::Open call to
   // pass the skipDeletedRecords option:
   BOOL CMySet::Open(UINT nOpenType, LPCTSTR lpszSql, DWORD dwOptions)
   {
       return CRecordset::Open(nOpenType, lpszSql,
           dwOptions | skipDeletedRecords );
   }
				

REFERENCES

See the documentation for CRecordset::Open() and CRecordset::IsDeleted(), as well as the MFC 4.2 Encyclopedia articles entitled "Recordset: How Addnew, Edit, and Delete Work" and "Recordset: Adding, Updating, and Deleting Records"

Modification Type:MajorLast Reviewed:12/10/2003
Keywords:kbDatabase kbprb kbprogramming KB156977