The RecordCount property of ADO's Recordset is always -1

xiaoxiao2021-03-05  29

The RecordCount property of ADO's Recordset is always -1

No .: QA002032 Establishment date: November 14, 1999 Last modified Date: January 2, 2004 Category: Visual Basic - Database

Operating System: NT Programming Tools: VB6, SQL Server Question: How do I judge that ADO's Recordset is empty? With the recordcount property, if there is no matter whether it is, the value is always -1. (MJ) Refer to Microsoft's Knowledge Base: "Q194973 PRB: Ado: RecordCount May Return-1", below is the article

Phenomenon ==== When the server is requested to request RecordCoun, -1 is returned. This is because Cursortype in ActiveX Data Objects (ADO) 2.0 is AdopenForwardOnly or AdoPendynamic. If it is ADO 1.5, only at Cursortype is AdopenForwardonly. If the results generated using OLEDB Provider for Jet and SQL Server may be different, this depends on the provider of the database. The provider may not support certain Cursortypes. When your CURSORTYPE is not supported, the provider will choose the Cursortype you requested. Please refer to your provider's documentation. Also note that all the combinations of LockType and Cursortype can work. Changing LockType will force Cursortype. Please make sure to use debugging to check the value of the CURSORTYPE. The reason ===== The record number may change in the dynamic cursor. The word ONLY cursor cannot return RecordCount. Solution ========== Use adopenkeyset (= 1) or adopenStatic (= 3) as a server-side cursor or client game. The client only uses AdoPenStatic as Cursortypes, regardless of what kind of Cursortype you choose. State ====== This form is designed.

More information ================ Repeat behavior steps ------------------------- 1. Open a standard .exe project in Visual Basic From the Project menu, choose References Select either the Microsoft Active Data Object 1.5 Library or the Microsoft Active Data Object 2.0 Library 2. Paste the following code in the form code window...: Option Explicit Dim rs As ADODB.Recordset Private Sub Form_Load () 'set up rs Set rs = New ADODB.Recordset rs.CursorLocation = adUseServer rs.Open "Select ProductID from products", & _ "Provider = Microsoft.Jet.OLEDB. 3.51; "& _" Data Source = d: /vb5_win95/nwind.mdb ", _ adOpenDynamic, adLockUnspecified Debug.Print rs.RecordCount End Sub 3. Replace the preceding Data Source with a Data Source on your computer Run the preceding form. And Note The Record Count. Change The Cursortype To AdopenForwardOnly and Note The Record. 4. Change The CursorLocation TO A DuseClient and Experiment With The Different Cursortypes. In All Cases The Correct Record Count Returns. 陈晓鸣 鸣: When the RecordSet record is open, if the parameter 3 (which is curSortype) is the keyboard index or the forward index (CURSORTYPE parameter is 0 or 0 OR) 1) In order to improve the processing speed, the Recordset Record is a one to give you, not you. The solution is to use dynamic or static index (CURSORTYPE parameter 2 or 3) Yao Lu, because in the C / S structure, the recordset is paging stored, when you request data from the server, it won't give you all data . It is best to use RS.Getrows () to all record rows Yang Xiaofeng, Dream Xiaofan's opinion: Set the CURSORLOCATION property of the ADO connection to the client: rs.cursorlocation = aduseclient is OK.

转载请注明原文地址:https://www.9cbs.com/read-33484.html

New Post(0)