CString s = "Select * from roomtype where typeid='"+m_sTypeID+"'";m_pRecordset=m_pConnection->Execute(_variant_t(s).bstrVal, NULL, adCmdText);m_sTypeID为变量
为什么无法执行?
还有其他的方法查找吗?

解决方案 »

  1.   

    先要看看你的SQL是否正确阿!~
      

  2.   

    m_pRecordset.CreateInstance("ADODB.Recordset");
    m_pRecordset->Open((const _variant_t)sql, _variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
      

  3.   

    用s.Format()写你的查询语句试试~
      

  4.   

    CString s;
    s.format("Select * from roomtype where typeid='%s',m_sTypeID);
    m_pConnection->Execute(s);
    if(!m_pRecordset->IsOpen())
    {  CString s;
      s.Format("Select * from roomtype where typeid='%s'",m_sTypeID);
      m_pRecordset->open(AFX_DB_USE_DEFAULT_TYPE,s,CRecordset::readOnly); 
    }       
      m_pRecordset->Requery();

      

  5.   

    上面是两种,最好用下面的记录集指针打开,直接用前者得不到返回值的,最好用它进行UPDATE,DELETE之类的批处理;
      

  6.   

    s.Format("Select * from roomtype where typeid='%s'",m_sTypeID);
    m_pRecordset =m_pConnection->Execute(_variant_t(s).bstrVal, NULL, adCmdText);
    检测通过,运行时在这中断
    是否由于我在前面已经打开了Recordset
      

  7.   

    monbo(晚风) :你的问题和我的一样,你找到解决方案了没有?
      

  8.   

    你应该使用
    try
    {
    }
    catch()
    {
    }使用ADO开发的嘛?
    如果是的话把最后一句改为,不需要返回值,如果出现问题,会抛掷异常到catch块中
    m_pConnection->Execute(_bstr_t(s), NULL, adCmdText);
      

  9.   

    我前段时间经常写类似程序,你最好能把你的程序多贴点出来,可能是前面某些地方有问题;把你定义变量m_pConnection,m_pRecordset 的代码贴出来,我没搞懂你调用时为什么用等号,这是指针变量啊
      

  10.   

    u can trys.Format("Select * from roomtype where typeid='%s'",m_sTypeID);
    if(m_pRecordset->State==adStateOpen)
       m_pRecordset->Close();
    m_pRecordset =m_pConnection->Execute(_bstr_t(s), NULL, adCmdText);
      

  11.   

    CString s = "Select * from roomtype where typeid=\'"+m_sTypeID+"\'";m_pRecordset=m_pConnection->Execute(_bstr_t(s).bstrVal, NULL, adCmdText);