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!

fastest way to loop through a recordset 1

Status
Not open for further replies.

hinchdog

Programmer
Feb 14, 2001
380
US
hi all. i've heard somewhere that looping through a recordset using " while ( !rs.EOF ).." is expensive becasuse it has to constantly check if the recordset it at the end. I have been doing this instead, but was wondering if it's alot of trouble not much (if any) gain.

while ( !rs.EOF )
{
aSites = '' + rs(0);
rs.MoveNext ;
i += 1;
}

for (i = 0; i < aSites.length; i++){

.....

this way i only have to check the recordset once. anyone have any opinions on this???
 
It depends what you want. If possible, use SQL rather than checking all recordset one by one. Else use objRS.getrows in VBScript.

The advantage is that you can close the recordset and DB connection right after you put the recordset into an array.

rsarray=objRS.getrows 'objRS is a recordset and rearray is an array.

Call Close ' call a subroutine to close the recordset and DB connection

numbercols=ubound(rsarray,1)
numberrows=ubound(rsarray,2)

For I=0 to numberrows
For J=0 to numbercols
whatever=rsarray(J,I)
next
next

Regards
 
/me echos TechnicalAnalysis

adds:
If all you're doing is throwing it into a table, the absolute fastest way to go through a recordset is to use the .GetString method. *I think* you can determine how many rows you can get with the GetString method, so you can page with it. Personally, I always use GetRows, because I've always felt that GetString was too hard to manipulate.

There are various other ways to speed up your ASP application... if you are interested in what I know, post back and I'll type up what I've learned :)

hth
leo
 
Alright -- I'll get on it...

I think I'll make it an FAQ...

I'll be sure to post again when I finish it. I'll try to finish it after the game :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top