经典ASP做while循环显示错误 [英] Classic ASP do while loop showing error

查看:123
本文介绍了经典ASP做while循环显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有简单html表的经典ASP页面,并且我想基于从数据库中提取的未知数量的记录来循环表行,但是,当我使用do / while循环来循环记录时,我收到一个错误消息,说BOF或EOF为True。我希望表格的其他每一行都可以替代背景颜色(我在CSS中设置的颜色)。

I have a classic ASP page with a simple html table, and I want to loop the table rows based on a unknown number of records pulled from the database, however, when I am looping the records with a do/while loop, I am getting an error saying that Either BOF or EOF is True. I want every other row of the table to alternate background colors (the colors I have set in CSS).

<% do while not rsTest.eof %>
<tr class="odd">
<td colspan="5"><%=(rsTest.Fields.Item("field").Value)%></td>
</tr>

<% rsTest.moveNext
if not rsTest.eof then 
count = count + 1 %>
<tr class="even">
<td colspan="5"><%=(rsTest.Fields.Item("field").Value)%></td>
</tr>
<% end if %>

<% count = count + 1 
rsTest.moveNext 
loop %>

根据浏览器,该错误发生在浏览器之前的最后一个 rsRoster.moveNext上循环。如果从数据库中提取的记录数是偶数,则循环不会出错,但是如果要提取的记录数是奇数,则该循环会出错。我尝试插入一些如果EOF,则什么都不做,否则执行代码,但是当我这样做时,检查EOF的代码似乎只是被忽略了。任何建议将不胜感激。

The error, according to the browser, is occuring on the last "rsRoster.moveNext" right before the loop. The loop doesn't error out if there are an even number of records being pulled from the database, but it errors if there are an odd amount of records being pulled. I have tried inserting some "if EOF then nothing, else execute code", but the code checking if EOF just seems to be getting ignored when I do that. Any suggestions would be appreciated.

推荐答案

我知道我对此不满意,但请尝试以下方法:

I know I am rusty on this one but try this:

<% 
  Dim oddFlag
  oddFlag = 1
  do while not rsTest.eof 
  if oddFlag=1 Then 
    oddFlag=0
    Response.write("<tr class='odd'>")
    Response.write("<td colspan='5'>")
    Response.write(rsTest.Fields.Item("field").Value)
    Response.write("</td></tr>")
  else 
    oddFlag=1 
    Response.write("<tr class='even'>")
    Response.write("<td colspan='5'>")
    Response.write(rsTest.Fields.Item("field").Value)
    Response.write("</td></tr>")
  end if
  rsTest.moveNext 
 loop 
%>

这篇关于经典ASP做while循环显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆