Microsoft KB Archive/189360

= HOWTO: Use a Fields Array in the Fields Option of GetRows Method =

Article ID: 189360

Article Last Modified on 3/2/2005

-

APPLIES TO


 * Microsoft ActiveX Data Objects 1.5
 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7

-



This article was previously published under Q189360



SUMMARY
The ActiveX Data Objects (ADO) reference for the GetRows method states that it is possible to provide an optional Fields array in the Fields Option to limit the columns returned by GetRows to one or more specified columns. This article demonstrates how to use this option because there is no example given in the ADO Help file.



MORE INFORMATION
The GetRows method has the following arguments:
 * Rows: Optional. A Long expression indicating the number of records to retrieve. Default is adGetRowsRest (-1).


 * Start: Optional. A String or Variant that evaluates to the bookmark for the record from which the GetRows operation should begin. One of the BookmarkEnum constants can be used for this argument.


 * Fields: Optional. A Variant representing a single field name or ordinal position or an array of field names or ordinal position numbers. ADO returns only the data in these fields.

Sample use of GetRows may look something like this:
 * vdata = oRs.GetRows(adGetRowsRest, adBookmarkCurrent, vFields)

Steps To Accomplish Task
 Create a Standard .EXE project in Visual Basic. Add a reference to the Microsoft ActiveX Data Objects Library.  Add the following sample code to the default form's Load method: 'This sample code demonstrates how to pass an array of field 'names to the GetRows Fields Option.

Dim cn As New Connection Dim rs As New Recordset Dim vFields As Variant Dim vdata as Variant

'This example is connecting to SQL Server's Sample Pubs database. cn.Open "driver={SQL Server};" & _ "server=;uid=;pwd= ;database=pubs" rs.Open "select * from authors", cn  ReDim vFields(1) vFields(0) = "au_fname" vFields(1) = "au_lname" vData = rs.GetRows(adGetRowsRest,, vFields)

For i = 0 To UBound(vdata, 2) - 1 Debug.Print vdata(0, i) & " " & vdata(1, i)  Next i

 Modify the code sample to use your server, user id, and password.

 Test. The first and last name of each author is displayed in the Immediate (Debug) window.</ol>

Keywords: kbhowto kbdatabase KB189360

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.