Solved

ODBC/CRecordset & Null characters

Posted on 1997-03-24
4
261 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:gnewman
  • 2
4 Comments
 
LVL 4

Expert Comment

by:mbhakta
ID: 1300637
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 ?
0
 

Author Comment

by:gnewman
ID: 1300639
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.
0
 
LVL 1

Accepted Solution

by:
rhgaracci earned 70 total points
ID: 1300640
Will RFX_Binary() work if the field type in the database table is text?  I'm under the impression that it only works if the field type is VARBINARY which I can't create in MS-Acess 2.0
0
 

Author Comment

by:gnewman
ID: 1300641
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 128
modThree challenge 4 96
How to convert MFC::CString to UTF8 wchar_t* 10 276
Bartender label printing - switch on and off graphics 3 54
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question