用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,但是不行,麻烦各位解决一下

解决方案 »

  1.   

    format出来的语句不行?? 为什么不行???
    你把format出来的SQL字符串拷贝到sql server的查询分析器中执行看看可不可以??
      

  2.   

    pCmd->CommandText=Format("select * from DidianTable where didian_name like '%s%%' ORDER BY didian_name ASC",qidian);
    这样吗,不行:
    error C2065: 'Format' : undeclared identifier
    Error executing cl.exe.
    开始我定义的CSting str,然后str.Format形成字符串,再pCmd->CommandText= str,不行。
      

  3.   

    不是这样,是str.Format.. 你运行了为什么不行? 报什么错误??
      

  4.   

    第一步,
    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();