FIX: GetRows Method of ADO Object Returns Incorrect Value (198528)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.1
  • ActiveX Data Objects (ADO) 2.5

This article was previously published under Q198528

SYMPTOMS

The GetRows method of an ADO recordset object moves the record pointer forward one row too many when dealing with greater than 100 rows. GetRows simply places the records from the recordset object into an array. After calling GetRows, the next unread record is supposed to become the current record. When getting 1000 rows, for example, the next record should be 1001, but instead it places the user on record 1002.

RESOLUTION

The user can call 100 records or less with GetRows rather then greater than 100.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This behavior is fixed in Active Data Objects version 2.1 and later.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a Standard EXE project in Visual Basic. Form1 is created by default.
  2. Add a CommandButton to form1.
  3. Add the following code to the click event of the command button. This assumes that you have a DSN called "Test" which points to an Access table called "test1" with greater then 1000 records. (Create table test1 in an access database with one column c1 (number)-Insert more than thousand records into the same):
          Dim conn As Object, rs As Object
          Dim myArray As Variant
          Set conn = CreateObject("ADODB.Connection")
          conn.open ("DSN=Test")
          Set rs = conn.Execute("select * from test1")
    
          myArray = rs.getrows(1000)
          ' uncomment the following line to receive correct value in MsgBox.
          'myArray = rs.getrows(100)
    
          MsgBox rs("c1")
          rs.Close
          Set rs = Nothing
          conn.Close
          Set conn = Nothing
    						
Note that the MsgBox displays 1002 when it should display 1001, which is the next record after 1000.

Modification Type:MinorLast Reviewed:3/14/2005
Keywords:kbADO210fix kbBug kbMDAC250fix KB198528