In the past two days, friends have often asked me, why my database has records, but RecordCount = -1, what is the cause? How to solve the problem of RecordCount = -1, please see the system holy land to explain it to you in detail.
Generally people use the following two methods to execute SQL statements:
Set Rs=Conn.Execute(SqlStr)
and
Set Rs=Server.CreateObject(“ADODB.RecordSet“)
Rs.Open SqlStr,Conn,CursorType,LockType
(See here for RecordSet object methods)
Since the default recordset cursor is a server cursor,
Rs.CursorLocation = adUseServer
So return Rs.RecordCount=-1,
The server cursor should be changed to a client cursor,
Rs.CursorLocation = adUseClient
Rs.Open SqlStr,Conn,CursorType,LockType
rs.cursortype
Cursor type recordcount property
ForwardOnly 0 (default) returns -1
Keyset 1 correct number of records
Dynamic 2 -1 or incorrect number of records, depending on data source
Static 3 correct number of records
So Rs.CursorLocation = 3
Use recordset.support("property name") to test whether the property is supported.