用access可以这样
sql.Format("select * from IndexTable where Index_Name like '%s%%' ORDER BY Index_Name ASC",qidian);
而我用的SQL 2000,语句是
pCmd->CommandText="select * from IndexTable where Index_Name like '%s%%' ORDER BY Index_Name ASC";
这个变量字符串没法添进去,我试过先用Format生成字符串,再付给CommandText,但是不行,麻烦各位解决一下
sql.Format("select * from IndexTable where Index_Name like '%s%%' ORDER BY Index_Name ASC",qidian);
而我用的SQL 2000,语句是
pCmd->CommandText="select * from IndexTable where Index_Name like '%s%%' ORDER BY Index_Name ASC";
这个变量字符串没法添进去,我试过先用Format生成字符串,再付给CommandText,但是不行,麻烦各位解决一下
你把format出来的SQL字符串拷贝到sql server的查询分析器中执行看看可不可以??
这样吗,不行:
error C2065: 'Format' : undeclared identifier
Error executing cl.exe.
开始我定义的CSting str,然后str.Format形成字符串,再pCmd->CommandText= str,不行。
CString sql;
sql.Format("select * from IndexTable where Index_Name like '%s%%' ORDER BY Index_Name ASC",qidian);
pCmd的CommandText好像是put_CommandText()吧,记不清了!
但是可以肯定的事,CommandText是一个bstr,所以,需要sql.allocsysstring();