
asp错误:循环不能用,提示记录不存在
我和它对视一下午了,没有发现什么不妥的地方啊!<%temp=gxpro.recordcountiftemp>5thentemp=5endif%><%forx=1togxp...
我和它对视一下午了,没有发现什么不妥的地方啊!
<%
temp=gxpro.recordcount
if temp>5 then
temp=5
end if
%>
<%for x=1 to gxpro.recordcount%>
<a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><img src="houtai/gxpropic/<%=gxpro("pic")%>" alt="<%=gxpro("name")%>" height="120" hspace="6" vspace="4" border="0"></a>
<%
gxpro.movenext
next
%>
错误类型:
ADODB.Field (0x80020009)
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
注意:数据库的记录确实存在,而且有三条
记录集没有错误,把这条循环语句删掉可以显示一条记录,不会有错误提示
.recordcount单独显示在页面上数据为3
整个原代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="data.asp"-->
<%
aaa=request.QueryString("key")
set gxshop=server.CreateObject("adodb.recordset")
sql="select * from gxshop where key=3"'&aaa
gxshop.open sql,conn,2,3
%>
<%
set gxpro=server.CreateObject("adodb.recordset")
sql1="select * from gxpro where key=3"'&aaa
gxpro.open sql1,conn,3,3
%>
……
<%if gxshop.eof or gxshop.bof then%><br>
……
<%else
gxshop("count")=gxshop("count")+1
gxshop.update%>
……
<!--#include file="gxnewpro.asp"--></td>
</tr>
</table></td>
</tr>
</table>
<br>
<%
if gxpro.eof and gxpro.bof then
%>
……
<%else%>
……
<%
temp=gxpro.recordcount
if temp>5 then
temp=5
end if
%>
<%for x=1 to gxpro.recordcount%>
<a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><img src="houtai/gxpropic/<%=gxpro("pic")%>" alt="<%=gxpro("name")%>" height="120" hspace="6" vspace="4" border="0"></a>
<%
gxpro.movenext
next
%></td>
……
<%for k=1 to gxpro.recordcount%>
<td width="262" height="20" style="font-size:12px;color:#FF6600" align="center">[ <a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><%=gxpro("name")%></a> ]</td>
<%if (k Mod 3)=0 then%>
</tr>
<tr>
<%end if%>
<%
gxpro.movenext
next
gxpro.close
%>
……
<%end if%>
<%end if%>
<br>
<!--#include file="foot.asp"-->
</body>
</html> 展开
<%
temp=gxpro.recordcount
if temp>5 then
temp=5
end if
%>
<%for x=1 to gxpro.recordcount%>
<a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><img src="houtai/gxpropic/<%=gxpro("pic")%>" alt="<%=gxpro("name")%>" height="120" hspace="6" vspace="4" border="0"></a>
<%
gxpro.movenext
next
%>
错误类型:
ADODB.Field (0x80020009)
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
注意:数据库的记录确实存在,而且有三条
记录集没有错误,把这条循环语句删掉可以显示一条记录,不会有错误提示
.recordcount单独显示在页面上数据为3
整个原代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="data.asp"-->
<%
aaa=request.QueryString("key")
set gxshop=server.CreateObject("adodb.recordset")
sql="select * from gxshop where key=3"'&aaa
gxshop.open sql,conn,2,3
%>
<%
set gxpro=server.CreateObject("adodb.recordset")
sql1="select * from gxpro where key=3"'&aaa
gxpro.open sql1,conn,3,3
%>
……
<%if gxshop.eof or gxshop.bof then%><br>
……
<%else
gxshop("count")=gxshop("count")+1
gxshop.update%>
……
<!--#include file="gxnewpro.asp"--></td>
</tr>
</table></td>
</tr>
</table>
<br>
<%
if gxpro.eof and gxpro.bof then
%>
……
<%else%>
……
<%
temp=gxpro.recordcount
if temp>5 then
temp=5
end if
%>
<%for x=1 to gxpro.recordcount%>
<a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><img src="houtai/gxpropic/<%=gxpro("pic")%>" alt="<%=gxpro("name")%>" height="120" hspace="6" vspace="4" border="0"></a>
<%
gxpro.movenext
next
%></td>
……
<%for k=1 to gxpro.recordcount%>
<td width="262" height="20" style="font-size:12px;color:#FF6600" align="center">[ <a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><%=gxpro("name")%></a> ]</td>
<%if (k Mod 3)=0 then%>
</tr>
<tr>
<%end if%>
<%
gxpro.movenext
next
gxpro.close
%>
……
<%end if%>
<%end if%>
<br>
<!--#include file="foot.asp"-->
</body>
</html> 展开
3个回答
展开全部
一楼的兄弟回答的不对
二楼的也不对
这不是死循环,而是循环时跑到了记录外面,然后我们调用了不存在的数据记录,结果产生了那样的结果
解决方法:
<%for x=1 to gxpro.recordcount%>
<%if not gxpro.eof and not gxpro.bof then
'这是我加的
%>
<a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><img src="houtai/gxpropic/<%=gxpro("pic")%>" alt="<%=gxpro("name")%>" height="120" hspace="6" vspace="4" border="0"></a>
<%
gxpro.movenext
else '这是我加的
exit for '这是我加的
end if '这是我加的
next
%></td>
……
<%''''''''''''''''''''''''''''''''''
你要加上关闭名为gxpro的recordset对象
%>
<%for k=1 to gxpro.recordcount
%>
<%
if not gxpro.eof and not gxpro.bof then
'这是我加的
%>
<td width="262" height="20" style="font-size:12px;color:#FF6600" align="center">[ <a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><%=gxpro("name")%></a> ]</td>
<%if (k Mod 3)=0 then%>
</tr>
<tr>
<%end if%>
<%
gxpro.movenext
'以下是我加的
else
exit for
end if
'以上是我加的
next
gxpro.close
%>
二楼的也不对
这不是死循环,而是循环时跑到了记录外面,然后我们调用了不存在的数据记录,结果产生了那样的结果
解决方法:
<%for x=1 to gxpro.recordcount%>
<%if not gxpro.eof and not gxpro.bof then
'这是我加的
%>
<a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><img src="houtai/gxpropic/<%=gxpro("pic")%>" alt="<%=gxpro("name")%>" height="120" hspace="6" vspace="4" border="0"></a>
<%
gxpro.movenext
else '这是我加的
exit for '这是我加的
end if '这是我加的
next
%></td>
……
<%''''''''''''''''''''''''''''''''''
你要加上关闭名为gxpro的recordset对象
%>
<%for k=1 to gxpro.recordcount
%>
<%
if not gxpro.eof and not gxpro.bof then
'这是我加的
%>
<td width="262" height="20" style="font-size:12px;color:#FF6600" align="center">[ <a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><%=gxpro("name")%></a> ]</td>
<%if (k Mod 3)=0 then%>
</tr>
<tr>
<%end if%>
<%
gxpro.movenext
'以下是我加的
else
exit for
end if
'以上是我加的
next
gxpro.close
%>
展开全部
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="data.asp"-->
<%
aaa=request.QueryString("key")
set gxshop=server.CreateObject("adodb.recordset")
sql="select * from gxshop where key=3"'&aaa
gxshop.open sql,conn,2,3
%>
<%
set gxpro=server.CreateObject("adodb.recordset")
sql1="select * from gxpro where key=3"'&aaa
gxpro.open sql1,conn,3,3
%>
……
<%if gxshop.eof or gxshop.bof then%><br>
……
<%else
gxshop("count")=gxshop("count")+1
gxshop.update%>
……
<!--#include file="gxnewpro.asp"--></td>
</tr>
</table></td>
</tr>
</table>
<br>
<%
if gxpro.eof and gxpro.bof then
%>
……
<%else%>
……
<%
temp=gxpro.recordcount
if temp>5 then
temp=5
end if
%>
<%for x=1 to gxpro.recordcount
if gxpro.eof then exit for'这是我给你加的 %>
<a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><img src="houtai/gxpropic/<%=gxpro("pic")%>" alt="<%=gxpro("name")%>" height="120" hspace="6" vspace="4" border="0"></a>
<%
gxpro.movenext
next
%></td>
……
<%
gxpro.movefirst'这是我给你加的
for k=1 to gxpro.recordcount
if gxpro.eof then exit for'这是我给你加的%>
<td width="262" height="20" style="font-size:12px;color:#FF6600" align="center">[ <a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><%=gxpro("name")%></a> ]</td>
<%if (k Mod 3)=0 then%>
</tr>
<tr>
<%end if%>
<%
gxpro.movenext
next
gxpro.close
%>
……
<%end if%>
<%end if%>
<br>
<!--#include file="foot.asp"-->
</body>
</html>
上边已经执行过for 了,现在的记录集指针已经到最后了,你现在再执行for 当然不正确
建议你在每个for 下边加一句
if gxpro.eof then exit for
你加上后再看看
上边的源码是我改过后的,你执行下看看
<!--#include file="data.asp"-->
<%
aaa=request.QueryString("key")
set gxshop=server.CreateObject("adodb.recordset")
sql="select * from gxshop where key=3"'&aaa
gxshop.open sql,conn,2,3
%>
<%
set gxpro=server.CreateObject("adodb.recordset")
sql1="select * from gxpro where key=3"'&aaa
gxpro.open sql1,conn,3,3
%>
……
<%if gxshop.eof or gxshop.bof then%><br>
……
<%else
gxshop("count")=gxshop("count")+1
gxshop.update%>
……
<!--#include file="gxnewpro.asp"--></td>
</tr>
</table></td>
</tr>
</table>
<br>
<%
if gxpro.eof and gxpro.bof then
%>
……
<%else%>
……
<%
temp=gxpro.recordcount
if temp>5 then
temp=5
end if
%>
<%for x=1 to gxpro.recordcount
if gxpro.eof then exit for'这是我给你加的 %>
<a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><img src="houtai/gxpropic/<%=gxpro("pic")%>" alt="<%=gxpro("name")%>" height="120" hspace="6" vspace="4" border="0"></a>
<%
gxpro.movenext
next
%></td>
……
<%
gxpro.movefirst'这是我给你加的
for k=1 to gxpro.recordcount
if gxpro.eof then exit for'这是我给你加的%>
<td width="262" height="20" style="font-size:12px;color:#FF6600" align="center">[ <a href="gxshoppro.asp?id=<%=gxpro("id")%>&key=<%=gxpro("key")%>" ><%=gxpro("name")%></a> ]</td>
<%if (k Mod 3)=0 then%>
</tr>
<tr>
<%end if%>
<%
gxpro.movenext
next
gxpro.close
%>
……
<%end if%>
<%end if%>
<br>
<!--#include file="foot.asp"-->
</body>
</html>
上边已经执行过for 了,现在的记录集指针已经到最后了,你现在再执行for 当然不正确
建议你在每个for 下边加一句
if gxpro.eof then exit for
你加上后再看看
上边的源码是我改过后的,你执行下看看
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
死循环吧?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询