pVal = (IDispatch**)&pRs;
这样改编译会过,不知能不能得到你想要的结果。

解决方案 »

  1.   

    _ConnectionPtr pConn;                          
       _RecordsetPtr pRs;
    是你访问数据库的变量,一般你只访问一个数据库,所以,这两个变量你可以定义为全局的变量,因为你一定只有一个与数据库的连接。pRs针对不同的操作再进行更新。
      

  2.   

    STDMETHODIMP CUser::UserOpen(IDispatch **pVal)
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here
     pConn.CreateInstance("ADODB.Connection");

    char buf[100];
    CString connectionstring,username,password,sql;
    connectionstring="Provider=SQLOLEDB;Data Source=";
    GetPrivateProfileString("System","ServerName","",buf,99,"c:\\BoTongOA.ini");
    connectionstring+=CString(buf)+";Initial Catalog=";
    GetPrivateProfileString("System","DatabaseName","",buf,99,"c:\\BoTongOA.ini");
    connectionstring+=CString(buf);
    GetPrivateProfileString("System","UserName","",buf,99,"c:\\BoTongOA.ini");
    username=CString(buf);
    GetPrivateProfileString("System","Password","",buf,99,"c:\\BoTongOA.ini");
    password=CString(buf); pConn->Open(_bstr_t(connectionstring),_bstr_t(username),_bstr_t(password),0); sql="select * from OF_DEPT";
    pRs=pConn->Execute(_bstr_t(sql),&vRowsAffected,adCmdText);
    *pVal=(IDispatch*)pRs;

    pRs->Close;
    pConn->Close; 

    return S_OK;
    }以上代码运行是正确的,但在VB调用其DLL时,其返回的RecordCount为-1,请问应该如何修改才可以使RecordCound返回其总的记录数。
      

  3.   

    sql="select * from OF_DEPT";
    pRs=pConn->Execute(_bstr_t(sql),&vRowsAffected,adCmdText);
    pRs->MoveLast();    //add this and try
    *pVal=(IDispatch*)pRs;
        
        
      

  4.   

    因为你的ado缺省是不能这样用的,她不支持行集的反取(也就是不能是forward-only)
    在它的open中的参数可以设置