PRB: CDBVariant Contains Wrong BOOL Value When Calling CRecordset::GetFieldValue()ID: Q230491
|
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.
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.
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.
The following steps use the SQL Server Pubs database as an example:
CDatabase db;
db.OpenEx(_T("Driver=SQL Server;Server=(local);Database=Pubs;UID=sa;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;
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 kbMFC kbODBC kbVC kbVC600 kbGrpVCDB
Version : winnt:6.0
Platform : winnt
Issue type : kbprb
Last Reviewed: May 7, 1999