Microsoft KB Archive/159956

= FIX: Dirty Flag Not Cleared During Edit or Update =

Article ID: 159956

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> </li></ul>

-

<div class="notice_section">

This article was previously published under Q159956

<div class="symptoms_section">

SYMPTOMS
When you use the Microsoft Foundation Classes (MFC) ODBC to update a record that has not been modified since the last call to CRecordset::Update, the fields within the record show up as dirty.

<div class="cause_section">

CAUSE
Neither the CRecordset::Edit function nor the CRecordset::Update function clear the dirty flag.

<div class="resolution_section">

RESOLUTION
Override CRecordset::Update and clear the dirty flags for your recordset after calling the base class CRecordset::Update.

<div class="status_section">

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual C++ version 5.0.

<div class="moreinformation_section">

MORE INFORMATION
The following sample code displays the problem. The second sample shows how to implement the workaround:

Sample Code 1
// m_pSet is a pointer to a CRecordset derived class, called CMySet, // that has a text member variable called m_Name.

m_pSet->Edit; m_pSet->m_Name = "NewName"; m_pSet->Update;

m_pSet->Edit; if( m_pSet->IsFieldDirty( &(m_pSet->m_Name) ) ) TRACE( "Name is dirty\n" ); // The next call will update the record, even though the data has // not changed. m_pSet->Update;

Sample Code 2
// Override CRecordset::Update and clear the dirty flags: BOOL CMySet::Update {     BOOL bReturn = CRecordset::Update; if (m_bCheckCacheForDirtyFields &&        !(m_dwOptions & optimizeBulkAdd)) {        SetFieldDirty(NULL, FALSE); }     return bReturn; }

Additional query words: kbVC420bug kbDSupport

Keywords: kbbug kbfix kbdatabase kbvc500fix KB159956

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.