数据库已连上
读取的时候出现中断的错误
这部分代码如下:
_CommandPtr m_pCommand;
  m_pCommand.CreateInstance("ADODB.Command"); 
  _variant_t vNULL;
  vNULL.vt = VT_ERROR;
  vNULL.scode = DISP_E_PARAMNOTFOUND;  m_pCommand->ActiveConnection = m_pConnection;
  m_pCommand->CommandText = "select datadir from Tab_record";
  m_pRecordset = m_pCommand->Execute(&vNULL,&vNULL,adCmdText);
错误好像就是出现在最后一句  m_pRecordset = m_pCommand->Execute(&vNULL,&vNULL,adCmdText);这里,
请问各位怎么解决这个问题?在此先行谢过

解决方案 »

  1.   

    前两个参数有问题吧? 没用过Command,但觉得你这样调用有点奇怪
    先把这两个参数分成两个变量来看看
      

  2.   

    m_pRecordset = m_pCommand->Execute(NULL,NULL,adCmdText);
      

  3.   

    _RecordsetPtr m_pRecordset;
    m_pRecordset.CreateInstance("ADODB.Recordset");m_pRecordset->Open("select * from Tab_record",_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);这样写呢,也会在 m_pRecordset->Open这里出现错误导致中断
      

  4.   

    见过很多和LZ最后一句一样的用法,应该没有错。帮LZ顶!
      

  5.   

    select * from Tab_record 这个语句之前 加一个 Use [你的数据库]试试?
      

  6.   

    这样用试试看
    ==================
    _CommandPtr m_pCommand;
    _RecordsetPtr m_pRecordset;
    CString csConn;//你的数据库连接字串
    CString csSql = "select datadir from Tab_record";
    //创建对象
    m_pCommand.CreateInstance(CComBSTR("ADODB.Command");//输入连接参数
    m_pCommand->put_ActiveConnection(_variant_t( (LPCTSTR)csConn));
    m_pCommand->PutCommandText(csSql.AllocSysString());
    m_pCommand->PutCommandType(adCmdText);
    m_pRecordset=m_pCommand->Execute(NULL,NULL,adCmdText);
      

  7.   

    呵呵,漏掉个括号。
    _CommandPtr m_pCommand;
    _RecordsetPtr m_pRecordset;
    CString csConn;//你的数据库连接字串
    CString csSql = "select datadir from Tab_record";
    //创建对象
    m_pCommand.CreateInstance(CComBSTR("ADODB.Command"));//输入连接参数
    m_pCommand->put_ActiveConnection(_variant_t( (LPCTSTR)csConn));
    m_pCommand->PutCommandText(csSql.AllocSysString());
    m_pCommand->PutCommandType(adCmdText);
    m_pRecordset=m_pCommand->Execute(NULL,NULL,adCmdText);
      

  8.   

    error C2065: 'CComBSTR' : undeclared identifier
    需要添加什么头文件吗
      

  9.   

    LS的老兄:
    1、m_pCommand->PutCommandText(csSql.AllocSysString());
    这句话可能会造成内存泄露吧,因为csSql转化之后,并没有回收机制
    我在测试程序的时候,发现我使用的语句会出现内存泄露的问题。
    应该使用::SysFreeString把内存给释放掉。
    2、_RecordsetPtr m_pRecordset;这个对象不需要创建吗?
      

  10.   

    http://blog.csdn.net/wang921718/archive/2007/07/19/1698490.aspx
    看看我的BLOG,希望能对你有帮助!