Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working off of an example that I got from a microsoft site so I figure that it should work. I'm having a problem with this line...
C++
SQLCHAR* query = "SELECT COUNT(*) FROM tblIP WHERE IP = '%s' AND IPStatus = '1' AND IPType = '3' AND IPMax ='0'",ipSrc == NULL ? "0" : ipSrc);

Here is the error message...
a value of type "const char *" cannot be used to initialize an entity of type "SQLCHAR *"

SQLCHAR* is n unsigned char and the SELECT statement is an const char..I've been wrestling with this for while now. any help is ppreciated. Thnk you.
Posted
Updated 16-Oct-11 9:43am
v2

Never assume that sample code posted to the internet will work "out of the box". Most samples are posted 'as is' with no claim as to their quality. Also, many samples may be based on a particular version of compilers and libraries and will only be compatible with those versions. One of the joys of samples like this is debugging them and so learning something new.
 
Share this answer
 
That is not a valid statement. It looks like it was originally a CString Format() or sprintf() statement and you turned it into a simple assignment.

The highlighted portion makes no sense in the context of an assignment statement.

SQLCHAR* query = "SELECT COUNT(*) FROM tblIP WHERE IP = '%s' AND IPStatus = '1' AND IPType = '3' AND IPMax ='0'",ipSrc == NULL ? "0" : ipSrc);

The %s is a formatting specifier.
 
Share this answer
 
Comments
Member 7766180 16-Oct-11 18:25pm    
Yes Chuck it was this statement which worked fine when I queryied the database that was on line. It was mySQL. It is now a local Access 2010 database. I've mde the connection, but now my SELECT statement no longer works! Wht is the problem? Thank you.
Chuck O'Toole 16-Oct-11 18:30pm    
Maybe I didn't understand your question or you misunderstood my answer. You said that you get a compiler error on the statement you showed. I explained why you get a compiler error and highlighted the portion that are illegal in the statement you posted. If your intent was to build a string containing the 'ipSrc' variable, you cannot use the assignment statement as written. You have to do something else. I offered that 'CString Format()' or 'sprintf()' was the most likely target of the string you posted. This is a completely different question that "my SELECT statement no longer works". As far as I can tell, you never even got to the point of discovering if the SELECT *works*, it doesn't even compile.
Member 7766180 16-Oct-11 19:11pm    
Thank you. Now my problem is wht is the syntax for a select statement. I tried quotes, parantheses, all kinds of things. How would I word my select statement? I'm connected to the access database, ODBC thats good. I have to be able to query it now.
Chuck O'Toole 16-Oct-11 19:24pm    
Have you tried googling "select syntax"? I got the answer to your question on the first try,
Member 7766180 16-Oct-11 19:49pm    
Chuck, I have been googling, All Day! Please point me to the link at least, because I can't seem to find it! Thank you.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900