The reason and solution of recordcount=-1

 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.

tutorial

 

  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.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326789221&siteId=291194637