定义了一个表user,字段为: name char(10),password char(10)
我现在企业管理器里用sql语句插入 insert into user ('john','pass').
然后在vc里面构造sql语句,
CString name="john",password="pass",sql;sql.Format("select * from user where name ='%s' and password='%s' ",name,password),
然后查询,可得不到记录?
用sql.Format("select * from user where name =%s and password=%s ",name,password)也不行,为什么?
谢谢!

解决方案 »

  1.   

    cstring::format 的 %s 应该对应一个字符串(char * 或者 const char * )而不是另一个cstring,如果这样建议强制转换或者使用char*类型。最好首先用AfxMessageBox显示出你的sql是否正确。
      

  2.   

    sql.Format("select * from user where name =\"'%s'\" and password=\"'%s'\"",name,password)
    name和password应该字符类型的字段吧?在SQL的select语句中应该用""或者''括起来。