Microsoft KB Archive/156977

= PRB: CRecordset Does Not Skip Deleted Records =

Article ID: 156977

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition

 Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q156977

<div class="symptoms_section">

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

<div class="cause_section">

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.

<div class="resolution_section">

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

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

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 ); }

<div class="references_section">