Microsoft KB Archive/230491

= PRB: CDBVariant Contains Wrong BOOL Value When Calling CRecordset::GetFieldValue =

Article ID: 230491

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q230491



SYMPTOMS
When calling the CRecordset::GetFieldValue method that accepts a CDBVariant object as a parameter and the target field in the database is a bit field, the BOOL value (m_boolVal) is incorrect.



RESOLUTION
Use an explicit type other then SQL_C_BIT, such as SQL_C_UTINYINT or SQL_C_SLONG, as the type of variable to bind to.

Please see the More Information for details.



STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.



MORE INFORMATION
The following steps use the SQL Server Pubs database as an example:

Steps to Reproduce Behavior
 Create an MFC Single Document Interface project with database header file support. Create a menu item or button event handler.  Type the following code in the handler and change the connect string to reflect your SQL Server database and you user account: CDatabase db; db.OpenEx(_T("Driver=SQL Server;Server=(local);Database=Pubs;UID= ;PWD= ;"));

CRecordset rs; rs.m_pDatabase = &db; rs.Open(CRecordset::forwardOnly, _T("SELECT * FROM authors"));

CDBVariant varField; rs.GetFieldValue(_T("contract"),varField); BOOL boolValue = varField.m_boolVal;

 Observe the value of boolValue. It will be incorrect.

Workaround
Use SQL_C_UTINYINT or SQL_C_SLONG explicitly in the CRecordset::GetFieldValue method. Replace the last two lines of the previous code block with one of the following: rs.GetFieldValue(_T("contract"),varField,SQL_C_UTINYINT); BYTE byteValue = varField.m_chVal; -or- rs.GetFieldValue(_T("contract"),varField,SQL_C_SLONG); BOOL boolValue = varField.m_boolVal;

Additional query words: boolean odbc

Keywords: kbdatabase kbprb KB230491

-

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

© Microsoft Corporation. All rights reserved.