Article ID: 197448 - Last Review: December 11, 2003 - Revision: 2.0 FIX: CRecordset "String Cannot Be Converted to Number" ErrorThis article was previously published under Q197448 SYMPTOMS
This article explains the consequences of altering the address assigned to
a CRecordset member variable. This problem can occur when the CRecordset
class uses numeric or decimal fields. If the internal buffer changes, the
following error message can occur during a call to CRecordset::Update():
String cannot be converted to number
CAUSE
Each field in a database that is bound to a CRecordset member variable has
a corresponding binding address stored in CRecordset::m_pvBindAddress. This
binding address is the location in memory where data for each field is
placed when ODBC retrieves a record. Once bound, the address of this column
must remain valid as long as the ODBC binding remains in effect. If this
address changes, the CRecordset class can display the following debug TRACE
message when retrieving a record:
Error: field address (column x) has changed
String cannot be converted to number
RESOLUTION
The MFC CRecordset Class Wizard binds high precision numeric and decimal
fields to CString member variables. The MFC CRecordset class keeps a
pointer to the CString internal buffer in CRecordset::m_pvBindAddress. If
you modify a CString member variable, the CString class may re-allocate
it's string buffer (for example, if you increase the size of the CString).
If this change occurs, the address stored in CRecordset::m_pvBindAddress
becomes invalid.
For example, the CString class can reallocate its internal memory if you make the following call to CString::Format(...): STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Visual Studio 6.0 Service Pack 3. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base: 194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why (http://support.microsoft.com/kb/194022/EN-US/ ) 194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed (http://support.microsoft.com/kb/194295/EN-US/ ) MORE INFORMATION
Internally, the CRecordset class checks CRecordset::m_pvBindAddress against
the class member field buffer to ensure it has not changed. If this
comparison fails, you get the "String cannot be converted to number" error.
The comparison is made in dbrfx.cpp on line 1049: APPLIES TO
| Article Translations
|
Back to the top
