m_pRecordset->Open("SELECT * FROM book where name like '"+cstr+"%'",_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);

解决方案 »

  1.   

    SQL语句不同数据库会有差异
    ACCESS的通用符号为*
    SQL SERVER的为%
      

  2.   

    "SELECT * FROM book where name like '"+cstr+"%'"
    最好用单独的变量来设置看看。
    CString strSQL;
    strSQL = "SELECT * FROM book where name like '"+cstr;
    strSQL += "%'";
      

  3.   

    SELECT * FROM book where name like '"+cstr+"%'"
    你编译能通过吗??应该不行吧
    CString querystr = "SELECT * FROM book where name like '"+cstr+"%'"_pRecordset->Open(_variant_t(querystr),_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
      

  4.   

    把SQL语句用变量单独保存,再进行格式转化在COM中,一般涉及变量就是Variant,涉及字符串就是BSTR的类型
      

  5.   

    _RecordsetPtr m_pRecordset=NULL;
    m_pRecordset->CreateInstace(__uuidof(Recordset));_bstr_t sql="SELECT * FROM book where name like '"+cstr+"%'";
    m_pRecordset->Open(sql",_variant_t((IDispatch*m_pConnection,true),
    adOpenStatic,adLockOptimistic,adCmdText);
    .....