Click here to Skip to main content
12,749,285 members (35,311 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 20 Oct 2005

How to Get an ADO RecordSet into an Array.

, 20 Oct 2005
Rate this:
Please Sign up or sign in to vote.
How to convert an ADO RecordSet to and Array.
<!-- Article Starts - DO NOT ADD HTML/BODY START TAGS-->


Often it is required to get the records retrieved in an SQL fetch into a recordset to an array. This is made possible using the GetRows method of the Recordset Object which inturn returns a variant array.


The procedure is explained below

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> 

Dim dbA As ADODB.Connection

Dim rsA As ADODB.Recordset


    Set dbA = New ADODB.Connection

    Set rsA = New ADODB.Recordset

    dbA.Open "DSN=tstDSN;UID=sa;PWD=pass;"


Dim csSql As String

csSql = "SELECT    * From EmployeeTable”


            Set rsA = dbA.Execute(csSql)

            If rsA.EOF = True And rsA.BOF = True Then

                GoTo exithandler

            End If


'Get this to Array.

Dim nNoOfReords as Integer

arrRecordArray = rsA.GetRows

nNoOfReords= UBound(vRecordArray, 2)+1


‘Now arrRecordArray contains the recordset in array format.


Consider the employee table with fileds empID, empName, empAge such that


empID              empName        empAge


1                      Smith                24

2                      Baiju                26

3                      Ragi                 26

4                      Pramod            23

5                      Bincy                25


Then the variant array structure will be


arrRecordArray(0,0)=1,  arrRecordArray(1,0)=Smith, arrRecordArray(2,0)=24

arrRecordArray(0,1)=2,  arrRecordArray(1,1)=Baiju, arrRecordArray(2,1)=26


i.e. the first argument specifies the FieldIndex and the second one specifies the RecordIndex.


The number of records returned may be found as

nNoOfReords= UBound(vRecordArray, 2)+1


hope this piece of information will be useful for you.


By Smith.S.Raj

Software Engineer

M-Squared, Technopark.



This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer
India India
Software Engineer,
Technopark, Kerala.

Rx 135 Owner
Yamaha Fan.

You may also be interested in...

Comments and Discussions

QuestionQuestions About "vRecordarray" Pin
Juan Rincon25-May-10 16:50
memberJuan Rincon25-May-10 16:50 
GeneralThanks!! Pin
winmedia11-Mar-07 4:15
memberwinmedia11-Mar-07 4:15 
Generalmost of us knew about this 7 years ago... Pin
Anonymous21-Oct-05 8:34
sussAnonymous21-Oct-05 8:34 
GeneralRe: most of us knew about this 7 years ago... Pin
Smith_TVPM27-Oct-05 8:22
memberSmith_TVPM27-Oct-05 8:22 
GeneralRe: most of us knew about this 7 years ago... Pin
Babs Iwarere27-Dec-07 22:56
memberBabs Iwarere27-Dec-07 22:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170215.1 | Last Updated 20 Oct 2005
Article Copyright 2005 by Smith_TVPM
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid