Reputation: 289
The SELECT statement is a const char and "query" has to be a SQLCHAR*
I've tried reinterpreting the cast but that doesn't seem to work. The code runs, even with this error, but I would like to get rid of the error. The line:
SQLCHAR* query = "SELECT tblIP.[IPAddress], tblIP.[IPStatus], tblIP.[IPType] FROM tblIP ORDER BY tblIP.[IPAddress] ASC;";
The Error:
IntelliSense: a value of type "const char *" cannot be used to initialize an entity of type "SQLCHAR *"
Upvotes: 0
Views: 4009
Reputation: 289
SQLCHAR* query = (SQLCHAR *)"SELECT tblIP.[IPAddress], tblIP.[IPStatus], tblIP.[IPType] FROM tblIP ORDER BY tblIP.[IPAddress] ASC;";
Upvotes: 2
Reputation: 57749
Try this:
char select_statement[] = "SELECT tblIP.[IPAddress], tblIP.[IPStatus], tblIP.[IPType] FROM tblIP ORDER BY tblIP.[IPAddress] ASC;";
Notice the [] after the variable name.
Or:
std::string select_statement = "SELECT tblIP.[IPAddress], tblIP.[IPStatus], tblIP.[IPType] FROM tblIP ORDER BY tblIP.[IPAddress] ASC;";
// And pass select_statement.c_str() to your function.
The issue is that the function that requires char *
wants a variable, an array, a mutable area of text. String literals have the type const char *
which is a pointer to constant data.
The compiler is complaining that you are passing a pointer to constant data to a function that wants a pointer to mutable data.
Upvotes: 0
Reputation:
Well, SQLCHAR can mean tons of different things. You have to at least mention what API you are using... Perhaps this is just a wide-char problem? Try this one:
SQLCHAR* query = L"SELECT tblIP.[IPAddress], tblIP.[IPStatus], tblIP.[IPType] FROM tblIP ORDER BY tblIP.[IPAddress] ASC;";
Upvotes: 0