CRecordset::GetFieldValue and incorrect string length.  
Author Message

PostPosted: Top

MFC >> CRecordset::GetFieldValue and incorrect string length.


I'm having an issue with using CRecordset::GetFieldValue to access a
column of floats in a SQL Server database. i'm using Visual Studio .net

The problem is the strings that are being returned are all 1 character
too long.
For example GetFieldValue returns the cstring "93.99999999999999",
which is 17 chars long, but if i call GetLength on the cstring it says
its 18 characters long.

When i stepped through CRecordset::GetFieldValueEx to see what was
going on, i noticed that getfieldvalueex, while setting the string
value, calls CString::GetBufferSetLength but has no corresponding

So i've changed my code to something like this

CString sVal;
while (!rs.IsEOF())
rs.GetFieldValue((short) 0, sVal);

and now all my strings are the right length.

So am i doing something fundamentally wrong in how i'm getting the
values from the database? or is this what i'm supposed to do?

Visual Studio332