Microsoft KB Archive/126134

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

Article ID: 126134

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft Foundation Class Library 4.2, when used with:
 * Microsoft Visual C++ 2.0 Professional Edition

-



This article was previously published under Q126134



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:

  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 );   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); }                        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 query words: 2.00 3.00

Keywords: kbbug kbdatabase kbfix KB126134

-

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

© Microsoft Corporation. All rights reserved.