我想根据变量来控制查询的条件,请问该怎么做!!!!
我的如下方法<1>
  char buf[256];
m_pSet.CreateInstance(__uuidof(Recordset));
         CString FieldName,str;
         FieldName = .....;
         str = ...........;
sprintf(buf,"select * from booklist where %s = %s",FieldNmame,str);
m_pSet->Open(_variant_t(buf),m_pConn.GetInterfacePtr(),
<2>
_RecordsetPtr pRst(__uuidof(Recordset));
CString strSql="select * from password";
CString strTemp=" where num = ";
strSql+=strTemp;
strSql+=num;
// AfxMessageBox(strSql);
BSTR bstrSQL = strSql.AllocSysString(); 
m_pSet->Open(bstrSQL,(IDispatch*)m_pConn,adOpenDynamic,adLockOptimistic,
                      adCmdText); 
以前的程序中实现过类似的查询,但是由于中毒,程序都丢失了,也记不清当时是怎么具体实现的了,现在用到以上方法,用MessageBox 看Sql语句正常,可是程序在调试运行时到m_pSet->Open()时提示Unhandle excetion。Kernel32.dll  什么什么的,不知是为什么,请路过的大侠指导一下!!!不盛感激!!

解决方案 »

  1.   

    try-catch 一下看看是什么事try
    {...
    }catch(_com_exception ee)
    {
    MessageBox(ee.ErrorMessage());
    }
      

  2.   

    执行到m_pSet->Open时就弹出错误停止执行了,看不到Catch的结果,
      

  3.   

    把(_variant_t(buf),改为_bstr_t(buf)
      

  4.   

    Unhandle excetion。Kernel32.dll 好象是无效指针
    看看m_pSet, m_pConn是否有效.
      

  5.   

    m_pset->Open(_sqlstr.c_str(),_variant_t(m_pcon.GetInterfacePtr()),adOpenDynamic,adLockOptimistic,adCmdText);