Link to home
Start Free TrialLog in
Avatar of gnewman
gnewman

asked on

ODBC/CRecordset & Null characters

MS Access has no trouble allowing the null character in a text field, and MS C++ has no trouble allowing the null character in a CString.  However, when I construct a CString with the null character in the middle, CString("Hi\0Joe",7) and then use AddNew to write that field into an Access database text field, the string gets truncated at the \0.

Anyone know a fix for this?
Avatar of mbhakta
mbhakta

There are several reasons why this is happening. One of the major reasons is your CString is nothing but an internal typecast of LPCSTR. A '\0' indicates a null termination and end of string. Hence, the problem.

May I ask you what you are trying to achieve with this technique ?
Avatar of gnewman

ASKER

In your DoDataExchange function use RFX_Binary() rather than RFX_Text().  RFX_Binary requires a parameter of type CByteArray&, so either convert your CString to a CByteArray or use CByteArray to manipulate your strings rather than CString.
ASKER CERTIFIED SOLUTION
Avatar of rhgaracci
rhgaracci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gnewman

ASKER

It should work as ODBC supports conversions between all character types and SQL_VARBINARY.  Try it.  If it doesn't work the way you want, you may need to make your own RFX_ function.