SQL Server存储过程:
CREATE procedure dbo.prc_Check
as
select A.表名,A.记录数 as 起始记录数,B.记录数 as 终止记录数,abs(A.记录数-B.记录数) as 相差记录数 from dtp_t1 A,dtp_t2 B
where A.表名 not like 'dtp%' 
and A.表名=B.表名 and A.记录数<>B.记录数 order by A.表名
GOVB代码:
Set oComm = New ADODB.Command
Set oRst = New ADODB.Recordset
oComm.ActiveConnection = oConn
oComm.CommandText = "prc_Check"
oComm.CommandType = adCmdStoredProc
Set oRst = oComm.Execute()
Debug.Print oRst.RecordCount得到的结果oRst.RecordCount = -1;
在查询分析器中执行exec prc_Check返回正确的记录集。

解决方案 »

  1.   

    用下面的代码也有同样的效果
    dim rs as ADODB.Recordset
    Set rs = New ADODB.Recordset
    rs.Open "exec prc_check", Conn, adOpenKeyset, adLockReadOnly, 1
    Debug.Print rs.RecordCount
      

  2.   

    用你的连接请将
    rs.Open "exec prc_check", Conn, adOpenKeyset, adLockReadOnly, 1
    改成
    rs.Open "exec prc_check", oConn, adOpenKeyset, adLockReadOnly, 1
      

  3.   

    楼主:
    用你的代码修改之后:
    '//加入这一句,游标要用客户端的才行。
    oConn..CursorLocation = adUseClient
    '//////
    Set oComm = New ADODB.Command
    Set oRst = New ADODB.Recordset
    oComm.ActiveConnection = oConn
    oComm.CommandText = "prc_Check"
    oComm.CommandType = adCmdStoredProc
    Set oRst = oComm.Execute()
    Debug.Print oRst.RecordCount