PRB: CRecordset Does Not Skip Deleted Records

Last reviewed: July 31, 1997
Article ID: Q156977
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++, 32-bit Edition, versions 4.2, 4.2b, 5.0

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"


Additional query words: Move MoveFirst MoveLast MoveNext MovePrev
Keywords : MfcDatabase kbprg
Technology : kbMfc
Version : 4.2 4.2b 5.0
Platform : NT WINDOWS
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 31, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.