Solved

ODBC/CRecordset & Null characters

Posted on 1997-03-24
4
264 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 Query 2 98
matchUp  challenge 9 125
Updating statistics with error notification email in SQL server 4 120
Problem to open Excel file 15 223
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

749 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