recordsetPtr的open方法 什么时候会一次返回所有记录到内存?
经常出现异常,错误消息为 对象已经使用  是怎么回事啊?

解决方案 »

  1.   

    不会一次返回所有记录,只能通过你的程序循环读取。
      pRs->Open("SELECT * FROM Employee ORDER BY lname", 
             "dsn=pubs;uid=sa;pwd=;", 
             adOpenStatic, adLockOptimistic, adCmdText);
          
          TESTHR(picRs->BindToRecordset(&rs));      while (!pRs->EndOfFile)
             {
          // Process data in the CCustomRs C++ instance variables.
             printf("Name = %s %s\n",
                (rs.m_ul_fnameStatus == adFldOK ? rs.m_ch_fname: "<Error>"), 
                (rs.m_ul_lnameStatus == adFldOK ? rs.m_ch_lname: "<Error>"));      // Move to the next row of the Recordset. 
          // Fields in the new row will automatically be 
          // placed in the CCustomRs C++ instance variables.
       
             pRs->MoveNext();
             }
      

  2.   

    这个recordsetPtr你有没有CLOSE?    if (pRstEmployee)
            if (pRstEmployee->State == adStateOpen)
                pRstEmployee->Close();
        if (pConnection)
            if (pConnection->State == adStateOpen)
                pConnection->Close();
      

  3.   

    _RecordsetPtr 使用
    _RecordsetPtr xxx(__uuidof(Recordset));  xxx->Open(strSQL.c_str(),pDestConn.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
    错误号 = 80040e05
    错误信息:IDispatch error #3077
    错误源:Microsoft OLE DB Provider for SQL Server
    错误描述:对象被打开。
      

  4.   

    #define RELEASE_XXX(p)\
    try{\
    if(p!=NULL){  if( p->GetState()==adStateOpen ) p->Close(); }\
    }catch(...)\
    {\
    ;\
    }
    如上 close的另数据不是一次返回,只能通过你的程序循环读取,是在内存读吗? 需要数据库吗?我是静态获取的,数据库改变不影响我的
      

  5.   

    示例:
    _variant_t vUsername,vID,vname; //变量声明
     _RecordsetPtr m_pRecordset;     //记录集
     CString strid;
     _ConnectionPtr connection;
     m_pRecordset.CreateInstance(__uuidof( Recordset )); //创建实例
     m_pRecordset->Open("SELECT * FROM users",connection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);//执行SQL语句,得到记录集, connection必须已和数m_pRecordset->Close();m_pConnection->Close();m_pRecordset=NULL;m_pConnection=NULL;
      

  6.   

    _RecordsetPtr p(__uuidof(Recordset));      

    p->Open( stringSql,pSrcConn.GetInterfacePtr(),adOpenStatic,adLockReadOnly,adCmdText);
    DWORD nCount = p->RecordCount;  

    RELEASE_RECORDSET( p);   // if openstatus close
    p.Release();
    p.~_com_ptr_t();