FIX: Date/Time Fields Fail to Update When Using a Dynaset

Last reviewed: September 18, 1997
Article ID: Q126134
2.00 WINDOWS NT kbprg kbfixlist kbbuglist

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), included with: Microsoft Visual C++, 32-bit Edition, version 2.0

SYMPTOMS

An attempt to update a date/time field using a CTime object will fail. The CRecordset::RFX_Date() doesn't work correctly, and the date/time field in the database table isn't changed. This problem occurs only when passing CRecordset::dynaset as the first parameter to the CRecordset::Open() member function.

CAUSE

The RFX_Date() function that takes a CTime object as a parameter fails to transfer the CTime data to its TIMESTAMP_STRUCT proxy before performing an update.

RESOLUTION

To work around this problem, follow these steps:

  1. In one of the header files, such as the CRecordset's header file, create the following function prototype:

       void RFX_Date2( CFieldExchange* pFX, const char* szName, CTime& value );
    
    

  2. In the CRecordset's .CPP file or elsewhere, add this RFX_Date2() definition:

       void RFX_Date2(CFieldExchange* pFX, const char *szName,
          CTime& value)
       {
        ASSERT(AfxIsValidAddress(pFX, sizeof(CFieldExchange)));
    
        if (pFX->m_nOperation==CFieldExchange::BindFieldForUpdate)
        {
                if(pFX->m_nFieldType == CFieldExchange::param)
                    return;
    
                //pFX-m_nFields hasn't been incremented yet so no need to
                // subtract 1 for indexing m_pvFieldProxy
                if (pFX->m_prs->m_pvFieldProxy[pFX->m_nFields] != NULL)
                {
                    // Fill buffer (expected by SQLSetPos) with new field data
                    TIMESTAMP_STRUCT* pts;
                    pts = (TIMESTAMP_STRUCT*)
                       pFX->m_prs->m_pvFieldProxy[pFX->m_nFields];
                    pts->year = (SWORD)value.GetYear();
                    pts->month = (UWORD)value.GetMonth();
                    pts->day = (UWORD)value.GetDay();
                    pts->hour = (UWORD)value.GetHour();
                    pts->minute = (UWORD)value.GetMinute();
                    pts->second = (UWORD)value.GetSecond();
                    pts->fraction = 0;
                }
           }
           RFX_Date(pFX, szName, value);
       }
    
    

  3. Modify the DoFieldExchange member function of the CRecordset class, replacing calls to RFX_Date with calls to the RFX_Date2 function described above.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was corrected in Microsoft Visual C++ version 2.1.

MORE INFORMATION

MFC Technote #43 contains more information about record field exchange (RFX) functions and CFieldExchange operations.


Additional reference words: 2.00 3.00
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: MfcDatabase
Keywords : MfcDatabase kbbuglist kbfixlist kbprg
Technology : kbMfc
Version : 2.00
Platform : NT WINDOWS
Solution Type : kbfix


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: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.