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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

objRS.MoveNext generates exception in a loop

Status
Not open for further replies.

csbdeady

Programmer
May 18, 2002
119
GB
Hi

We're using the standard

While not objRS.EOF
...
objRS.MoveNext
Wend

However if we embed the object inside another While...Wend then it fails with an exception error, eg:

While not objRS.EOF
Response.Write "<tr>"

While PersonCount < 4
Response.Write "<td>some stuff from a database</td>"
PersonCount = PersonCount + 1
objRS.MoveNext
Wend

Response.Write "</tr">
Wend

If we replace the inner While...Wend with a For...Next we get the exact same problem.

Any thoughts?
Ta!
-Colin
 
Shouldnt your logic look like this:

While not objRS.EOF
Response.Write "<tr>"

While PersonCount < 4
Response.Write "<td>some stuff from a database</td>"
PersonCount = PersonCount + 1
Wend

Response.Write "</tr">
objRS.MoveNext
Wend

-VJ
 
No, my logic is correct.

Written as you suggest we get three identical records on the same row in three cells.

What we need to do is say:

1) Each row contains a maximum of 3 cells
2) Each cell contains different data

Therefore we need to count from 1 to 3 for the cells, moving to the next record each time we do so.
 
ahah! By jove I think you have it;)

If I combine it all together I should get:

PersonCount = 1
RowCount = int( objRS.count / 3 )

For i = 1 to RowCount

While PersonCount < 4 and not(objrs.eof)
Response.Write "<td>some stuff from a database</td>"
PersonCount = PersonCount + 1
objRS.MoveNext
Wend

Next
 
oh and obviously add in the lines containing Response.Write "<tr>" and ..</tr>
 
I'm not sure about code logic here... where do you reset PersonCount, display <tr></tr> etc.

Do you want to display recordset results in 3-column table, each row one cell?

Btw. don't use While.. Wend (use Do While... Loop instead) and don't get much addicted to While blah and blah2 (because ASP doesn't short-circuit logical expressions).
 
It's ok Vongrunt, I've missed out 80% of the code to keep the examples short, hence missing the info you describe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top