Click here to Skip to main content
13,049,233 members (72,423 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi Guys,

I am facing a weird problem to put the database query in CString Format with
Unicode defined.

I am giving a simple example of my problem.
CString str1;
int value = 123;        
str1.Format(_T("select * from Table Where Max > %d"), value);
Getting output only 1st character of entire string.
Output-> "s"  
instead of -> "select * from Table Where Max > 123"

I also tried this one but It's not getting integer variable and displaying like this:
str1.Format((LPCTSTR)("select * from Table Where Max > %d"), value);
OutPut-> "select * from Table Where Max > %d"

Please give me some solution because I tried everything but I didn't get where I did
Posted 10-Jul-12 4:00am
Updated 10-Jul-12 4:05am
nv3 10-Jul-12 10:45am
I'd check two things:

Is str1 defined as CString or CStringA or CStringY?

Is UNICODE and _UNICODE defined?

The latter problem would be my guess, so the Windows headers think they compile for Unicode and MFC headers think they compile of MBCX and hence select the wrong library.
saqib.akhter 10-Jul-12 11:04am
Thanks for reply..
but I got a solution that unicode display string setting was not enable that's why it happened.

Thanks for your investigation that could also help me in future...

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I got solved myself actually I just did silly mistake.
There is a one unicode setting has to be enable in Visual Studio.

Here is the solution:

Check the following setting in Visual Studio:
Check Display unicode strings checkbox.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 10 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100