• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 900
  • 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?
0
dgormley
Asked:
dgormley
1 Solution
 
dfu23Commented:
0
 
SquareHeadCommented:
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...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GoofyDawgCommented:
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
next

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

-- SquareHead
0
 
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.
0
 
dfu23Commented:
Eh, life goes on ...
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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