简体   繁体   English

记录计数返回值-1

[英]Recordcount returns value of -1

I have the below code which retrieves data correctly however always return a value of -1 for rs.RecordCount. 我有以下代码可以正确检索数据,但是对于rs.RecordCount总是返回-1的值。 Please assist. 请协助。

    Sub TEST()

        Dim rs As Object
        Set rs = CreateObject("ADODB.Recordset")

        Dim SQLSTR As String, MYVAL As String
        MYVAL = InputBox("Enter Query")
        SQLSTR = " " & MYVAL & ""
        CONNECT_TO_DWHS
        rs.Open SQLSTR, PERSONALDBCONT

        ActiveSheet.Cells(2, 1).CopyFromRecordset rs
        ActiveSheet.Cells(1, 1).Select

            Debug.Print rs.RecordCount

        CLOSE_CONNECTION_TO_SQL


    End Sub

The ADO Recordsets will ever show this, until they've jumped to the end the first time. ADO记录集将始终显示此内容,直到它们第一次跳到末尾为止。 So just use rs.Movelast, then rs.MoveFirst. 因此,只需使用rs.Movelast,然后使用rs.MoveFirst。

Now it should be OK... 现在应该可以了...

Hope this helps 希望这可以帮助

rs.CursorType = 3似乎可以工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM