解决database - Classic ASP - BOF
2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址:https://cloud.tencent.com/act/cps/redirect?redirect=1062
2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址:https://www.aliyun.com/minisite/goods
I am trying to run two WHILE NOT loops for a recordset. One of the loops counts the number of items whilst the other prints the results. I cannot alter the SQL query, so this is the counting method I'm left with.
setPeopleCount = 0
While NOT rsSetContents.EOF
setPeopleCount = setPeopleCount + 1
rsSetContents.MoveNext
Wend
While NOT rsSetContents.EOF
Response.Write rs.Fields("exampleItem")&"<br>"
rsSetContents.MoveNext
Wend
My problem is running the two loops. After the first loop has finished the count, the record cursor is at the end of the file, so when the next loop needs to run - it doesn't because EOF is true.
How can I reset the cursor back to the beginning of the file so the second loop can run?
database asp-classic vbscript ado resultset|
this question edited Dec 20 '11 at 22:45 Jonathan Allen 34.1k 51 174 343 asked Dec 20 '11 at 22:41 TheCarver 8,553 18 66 125 1 Why do you need the count first? – John Saunders Dec 20 '11 at 22:43 Why don't you get the count in a seperate statement like SELECT COUNT ? Or Even use GetRows() and use UBound(GetRowsArray,2) to get the count of records. – Control Freak Dec 22 '11 at 9:22
|
3 Answers
3
解决方法
You can use MoveFirst.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms677527(v=vs.85).aspx
|
this answer answered Dec 20 '11 at 22:45 Jonathan Allen 34.1k 51 174 343 Thanks, consider yourself a tick (when 7 minutes is up) – TheCarver Dec 20 '11 at 22:49
|
Could you not count on the bottom loop? Or perhaps read the records into an object array then you are free to iterate over it as many times as u want
|
this answer answered Dec 20 '11 at 22:48 RockThunder 146 4 Unfortunately not, I need to use the count before the second loop starts. I've just used rs.MoveFirst and it worked. Thanks anyway – TheCarver Dec 20 '11 at 22:50
|
The MoveFirst
requires proper cursor on the recordset - if for example you'll change to different database the default cursor might change and the code might fail.
I would suggest you to store the values while counting, thus save the second loop:
setPeopleCount = 0
Dim exampleItems()
ReDim exampleItems(-1)
While NOT rsSetContents.EOF
setPeopleCount = setPeopleCount + 1
ReDim Preserve exampleItems(UBound(exampleItems) + 1)
exampleItems(UBound(exampleItems)) = rs("exampleItem")
rsSetContents.MoveNext
Wend
'instead of a loop, just this:
Response.Write(Join(exampleItems, "<br />"))
|
this answer answered Dec 21 '11 at 13:05 Shadow Wizard 50.2k 15 92 140
|
相关阅读排行
- 1ASP错误类型:Microsoft JET Database Engine (0x80040E09) 不能更新。数据库或对象为只读。
- 2[asp连接access错误]错误类型:Microsoft JET Database Engine (0x80004005) 未指定的错误
- 3asp连接Access出现Microsoft JET Database Engine (0x80004005) 未指定的错误
- 4ASP解决方案-Microsoft JET Database Engine(0x80004005)未指定错误
- 5asp + Access 常见的数据库访问失败问题 Microsoft JET Database Engine 错误 '80004005' 解决办法
相关内容推荐
最新文章
- 1rpmdb: Thread died in Berkeley DB library
- 2SAP Netweaver和Hybris的数据库层
- 3【Oracle Database 12c的新特性】
- 4linux下mysql命令(授权用户 基本操作)
- 5Oracle:How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- 6【转载】Using the Entity Framework Repository and UnitOfWork Pattern in C# ASP .NET