• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 905
  • Last Modified:

return SQL results into array

Say you dont know how many items are in your database and you want to return the results into an array. I understand you have to count the number of records then use something like i = 1 to x where x is the number of records counted.
What I want, which my brain wont let me concentrate enough to figure out is to return the results of a query into an array where I can use it several times within one asp page.

Who cares to help?
1 Solution
Easiest way is to use the ADO GetRows method...

Set oRS = oConn.Execute("Select * from members")

if not(oRS.EOF) then

arrayRS = oRS.GetRows()


arrayRS is now a 2-dimesional array...
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Actually, to get a count of "records" or elements of an array, you needn't do a loop. Simply do this:

numRecs = UBound(myArray, 2) + 1

UBound is a VBScript function that returns the index of the last element in an array. The "2" parameter specifies the y-direction or "row" direction of a 2-d array (if you want a field count, do the same thing but use 1 as your param). We add 1 to the UBound value because VBScript arrays are 0-based, so your total records will be 1 more than what UBound returns.

Also, using UBound, you can loop through your array without caring about when you've gotten to the last record:

for i = 0 to UBound(myArray, 2)
...do stuff

this would work even if the base is not 0
num = Ubound(arr) - LBound(arr) + 1
@dfu23 -- sorry, didn't mean to duplicate your suggestion, I neglected to follow your link above...

-- SquareHead
dgormleyAuthor Commented:
Thanks everyone for submitting answers, I chose Squarehead since he/she typed what I was looking for. The links did help but after reading squarehead's my brain clicked and poof, i solved it. Thanks.
Eh, life goes on ...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now