SELECT语句是一个const char,“query”必须是SQLCHAR*
我试过重新解释转换,但这似乎不起作用。代码运行,即使有这个错误,但我想摆脱错误。这一行:
SQLCHAR* query = "SELECT tblIP.[IPAddress], tblIP.[IPStatus], tblIP.[IPType] FROM tblIP ORDER BY tblIP.[IPAddress] ASC;";
错误:
IntelliSense:类型为“const char *”的值不能用于初始化“SQLCHAR *”类型的实体
答案 0 :(得分:2)
SQLCHAR* query = (SQLCHAR *)"SELECT tblIP.[IPAddress], tblIP.[IPStatus], tblIP.[IPType] FROM tblIP ORDER BY tblIP.[IPAddress] ASC;";
答案 1 :(得分:0)
嗯,SQLCHAR可能意味着很多不同的东西。你必须至少提到你正在使用的API ...也许这只是一个广泛的问题?试试这个:
SQLCHAR* query = L"SELECT tblIP.[IPAddress], tblIP.[IPStatus], tblIP.[IPType] FROM tblIP ORDER BY tblIP.[IPAddress] ASC;";
答案 2 :(得分:0)
试试这个:
char select_statement[] = "SELECT tblIP.[IPAddress], tblIP.[IPStatus], tblIP.[IPType] FROM tblIP ORDER BY tblIP.[IPAddress] ASC;";
注意变量名后面的[]。
或者:
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.
问题是需要char *
的函数需要一个变量,一个数组,一个可变的文本区域。字符串文字的类型为const char *
,它是指向常量数据的指针。
编译器抱怨您正在将指向常量数据的指针传递给想要指向可变数据的指针的函数。