Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a range of records into an array

Status
Not open for further replies.

Faheemi

Programmer
Sep 2, 2001
59
HK
Hello friends,

I want to get a range of records from a recordset into an array. I know using GetRows method we can return a particular set of records from the start of the recordset like record 1 to 20 or 1 to 30. But I want to return records in a range like 10 to 20, 30 to 40 or whatever range.

Please help give me a resolution for my problem.

Many thanks

Faheem Hameed
 
Assigning the values(below)...


Dim dict, i
Set dict = Server.CreateObject("scripting.dictionary")
i = 1

Dim conn, rs
set conn = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")

'open db connection and recordset to select data from records 1 through 50

Do while not rs.EOF
dict.add ("key" & i), (rs("firstName") & rs("lastName"))
rs.movenext
loop

rs.Close
conn.Close




Reading Page(below)...


Dim starting 'User defined starting number such as 20
Dim ending 'User defined ending number such as 30

starting = request.querystring("UserDefinedStartingValue")
ending = request.querystring("UserDefinedEndingValue")

for i = starting to ending '20 to 30
Response.write(dict(i) & &quot;<BR>&quot;)
Next



This should be your solution. If I misunderstood you, please clearify a little more.
-Ovatvvon :-Q
 
Dear Ovatvvon,

Thanks for your input. My intention of this post is to display the recordset values quickly and efficiently. (ie in shortest duration of time and consuming less server resources).

I was told and exprimented that GetRows is a best method to fulfill my intention. In my code I am opening the recordset and returning it into an array using the GetRows method and closing the recordset as soon as possible (since keeping the recordset opened consumes server resources)

But in my case the whole record set is returned to the array. I affraid if the recordset returns a 100 thousand records it got put into the array that may make server performance worse.

That's why I am looking for a way around using GetRows or a Similar method to get just only a particular records.

So please let me know if you had accomplished this earlier.

Thanks a lot,

Faheem Hameed

 
Oh,
can't you just declare in the sql statement which rows to get?

sql = &quot;SELECT * FROM myTable WHERE (((myTable.PrimaryKey)>=10) And ((myTable.PrimaryKey)<=30));&quot;

That will only get rows 10 to 30 from the recordset.

This what you're looking for? -Ovatvvon :-Q
 
...or you could use:

rs.PageSize = varNumberOfRecords
rs.AbsolutePage = varPageNum
arrResults = rs.getrows(varNumberOfRecords)

which has the added bonus that if some of your records have been deleted, it will still return the same amount of records...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top