Skills | solve
phenomena
Returns-1 when Recordcoun is requested on the server side. This is because the CursorType in ActiveX Data Objects (ADO) 2.0 is adopenforwardonly or adopendynamic.
If it's ADO 1.5, it only happens when CursorType is adopenforwardonly. If you use OLE DB Provider for Jet and SQL Server, the results may vary, depending on the provider of the database.
Some cursortypes may not be supported by the provider.
when the CursorType you choose is not supported, the provider will choose the CursorType closest to the one you requested. Please refer to your provider's documentation. In addition, please note that
not all combinations of locktype and CursorType can work at the same time.。 Changing the LockType will force the CursorType to change. Make sure you use debugging to check the value of the CursorType.
reason
The record number may change in a dynamic cursor. The forwardonly cursor cannot return RecordCount.
Solutions
Use either adOpenKeyset (=1) or adOpenStatic (=3) as either a server-side cursor or a client cursor. The client only uses adOpenStatic as cursortypes, regardless of what kind of cursortype you choose.
State
This form is determined by design.
===============================================================================
linked documents help understand resolution
an explanation of "1" and another "1" in Rs.Open sql,1,1
Rs.Open sql,1,1 can also be written
Rs. CursorType = 1
Rs. LockType = 1
Rs.Open SQL
Where CursorType represents the records returned from a table or from a SQL query result.
This parameter has four values, respectively:
adOpenForwardOnly (=0)
Indicates that only the record is allowed to move forward between records in a recordset. This is the default value. (Read only, and the current data record can only move down)
adOpenKeyset (=1)
Reflects changes or deletions made by other users on records, but does not reflect actions by other users to add new records. (Read only, the current data record can move freely)
adOpenDynamic (=2)
Reflect changes or deletions to records made by other users, including new records added. (Can read and write, the current data record can move freely)
adOpenStatic (=3)
Does not reflect other user changes to the record, add, delete action. (Can read and write, the current data record can be moved freely, you can see the new record)
LockType represents the type used by the data provider to lock a database when the recordset is opened:
adLockReadOnly (=1)
Data cannot be changed, default lock type, Recordset is read-only, records cannot be modified
adLockPessimistic (=2)
Pessimistic locking, when a record is modified, the data provider attempts to lock the record to ensure that it is successfully edited. Lock the record immediately as soon as the editor starts. (data providers lock records when they start editing data)
adLockOptimistic (=3)
Optimistic locking is not locked until the update record is submitted with the Update method. (The data provider locks records only when the Update method is invoked)
adLockBatchOptimistic (=4)
Bulk optimistic locking allows multiple records to be modified, and records are locked only after the UpdateBatch method is invoked. (For batch modification)