BOOL CXYZAdo::OpenTable(CString strTable,CString strcolmn)
{
CString strSql;
strSql = "select * from " + strTable+"where Partname="+strcolmn+; 
一个数据查询函数,两个参数是表名和查询条件,正确的sql语句怎么写?

解决方案 »

  1.   

    干脆这样:
    strSql.Format("select * from %s where Partname='%s'", strTable, strcolmn);
    简洁明了,多好。:P
      

  2.   

    _bstr_t strSql;
    strSql = "select * from strTable where Partname='"+strcolmn+"'; 
      

  3.   

    strSql.Format("select * from %s where Partname='%s'", strTable, strcolmn);
      

  4.   

    用ADO的方式连接数据库,最后用_ConnectionPtr 的对象执行和打开SQL语句。我也是刚接触VC和SQL我喜欢用ADO连数据库,比较灵活。
      

  5.   

    strSql.Format("select * from %s where Partname='%s'", strTable, strcolmn);
    这个方法好用,谢谢!
    能简单跟我说一下 format的用法吗?msdn 看不大懂
      

  6.   

    Format就是把其他变量转换为字符串
    %s表示字符串变量,相当于连接字符串