Click to See Complete Forum and Search --> : How to loop through records in Asp.Net


akrashdi
04-23-2004, 05:43 PM
Hi,

I used to do following in Classic ASP. How to do this thing in ASP.Net?

__________________________

While not MyRecordset.EOF

some coding here where I wanna use "MyRecordset(productID).Text"

Recordset1.MoveNext()
wend
___________________________


Regords

PeOfEo
04-23-2004, 05:48 PM
what are you trying to do first of all. Looping through records might be a crappy way to do it since asp.net has a repeater control, data readers, data grids, and other stuff built in that will allow you to not have to use a loop through a recordset, or loop an sql statement. Infact you have probabbly used tons of loops in asp classic, I have maybe used two with asp.net because I really do not need them that often.

akrashdi
04-24-2004, 01:35 PM
Thanks,

Actually what I wanna do is, I wanna loop through each record and use its value in SELECT statement.

For example when cursor is at record # 1 the value I get from it is "Sedan" . I wanna use this value to get all the records from another table based on some crieteria.

and then cursor will move to record # 2 , then its value will be, say, "Van". then same process which was with record 1.

How to accomplish that with Repater control? and also, do you think that adding dynamic rows will help? I have no clear idea about it.

Appreciated...

Regards,

PeOfEo
04-25-2004, 10:15 PM
I am going to do an experiment real fast. Yes, you can use an and in an sql statement where statement.
select this from this where this = this and this = this orderby this.
You can chance the value of your where and resend it and put it back in the repeater. That make sence?
select value from table where record=" & request.querystring("record") & " and car=" & request.querystring("type") & " orderby price desc

But keep those to numeric values, I tend to get tons of errors when I start playing with strings, even if it is a string type variable unless I use a text box or something to hold it which is a pain in the butt... but that seems to be the only time I can make a string work.

CardboardHammer
04-26-2004, 08:59 AM
One is better off using a JOIN rather than making queries while looping through another record set. I've recoded such loops to JOINs, and the performance boost was dramatic: from utter suckage to blazing fast.