简体   繁体   English

RecordCount属性不起作用

[英]RecordCount Property not working

This is my code : 这是我的代码:

Dim conServer As ADODB.Connection
Dim rstResult As ADODB.Recordset
Dim strSQL As String
Set conServer = New ADODB.Connection
conServer.ConnectionString = "PROVIDER=SQLOLEDB; " _
& "DATA SOURCE=192.168.0.204; " _
& "INITIAL CATALOG=REPORTDB2; " _
& "User ID=sa;" _
& "Password="

conServer.Open

Set rstResult = New ADODB.Recordset
strSQL = "set nocount on; "
strSQL = strSQL & "select *  from Table1;"
rstResult.ActiveConnection = conServer

rstResult.Open strSQL

MsgBox rstResult.RecordCount, , rstResult.Fields(1).Value

With rstResult
    .MoveFirst
    Do Until rstResult.EOF
       Debug.Print abc & "," & .Fields(0) & "," & .Fields(1).Value
      .MoveNext
    Loop
End With

The MSGBOX Line showing me -1 as a RecordCount, but the same time rstResult.Fields(1).Value showing the first records value. MSGBOX行显示我-1为RecordCount,但同时rstResult.Fields(1).Value显示了第一个记录值。 Even I check through "do until...loop" all the records in msgbox or in debug window are perfectly showing. 甚至我通过“ do ...... loop”检查都可以完美显示msgbox或调试窗口中的所有记录。 The problem is it is not displaying or working recordcount property. 问题是它不显示或不起作用recordcount属性。

You cannot use RecordCount in that way. 您不能以这种方式使用RecordCount

It will give you the correct number of records only after you have looped through all records, but not before you have looped through the records. 只有遍历所有记录之后,它才会为您提供正确数量的记录,但遍历这些记录之前 ,不会给您正确的记录数。

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

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