C++连接mysql查询连接字符串有关问题
C++连接mysql查询连接字符串问题
利用combobox选中的值去数据库查询,可是连接字符串的时候报错:
error C2678: 二进制“+”: 没有找到接受“const char [33]”类型的左操作数的运算符(或没有可接受的转换)
红色部分是连接, 请问该怎么连接? 谢谢!!
------解决方案--------------------
------解决方案--------------------
常量字符串之间不能这么拼接,你可以把"select a from testmfc where a= '"先赋给string类型变量,然后再用这个变量拼接应该就可以了
利用combobox选中的值去数据库查询,可是连接字符串的时候报错:
error C2678: 二进制“+”: 没有找到接受“const char [33]”类型的左操作数的运算符(或没有可接受的转换)
红色部分是连接, 请问该怎么连接? 谢谢!!
CString strID;
GetDlgItemText(IDC_COMBO1,strID);
MYSQL *conn = new MYSQL;
conn = mysql_init(NULL);
MYSQL_RES *result;
MYSQL_ROW row;
conn = mysql_init(NULL);
mysql_real_connect(conn,"localhost","root","qwedcxz","test",3306,NULL,0);
mysql_query(conn,"select a from testmfc where a= '"+strID+"'");
result=mysql_store_result(conn);
row = mysql_fetch_row(result);
CString str;
char * charpoint ;
charpoint = row[0];
str = charpoint;
m_a.SetWindowTextW(str);
------解决方案--------------------
conn = mysql_init(NULL);
mysql_real_connect(conn,"localhost","root","qwedcxz","test",3306,NULL,0);
char sqlstr[1024];
sprintf(sqlstr,"select a from testmfc where a=%s'",strID);
mysql_query(conn,sqlstr);
result=mysql_store_result(conn);
row = mysql_fetch_row(result);
------解决方案--------------------
常量字符串之间不能这么拼接,你可以把"select a from testmfc where a= '"先赋给string类型变量,然后再用这个变量拼接应该就可以了