ASP rs输出问题
%rs.open"selecttop20*fromnewswhereBigClassName='测试新闻'orderbyAddDatedesc",conn,1,1i=-1...
% rs.open "select top 20 * from news where BigClassName='测试新闻' order by AddDate desc ",conn,1,1
i=-1
do while not rs.eof
%>
<td onMouseOver="this.style.backgroundColor='#EEF7FF';return true;" onMouseOut="this.style.backgroundColor='#ffffff';" width="25" height="18"><img src="images/icon_new.gif" width="18" height="15"></td>
<td width="279" height="18"><a href="shownews.asp?id=<%=rs("id") %>" target="_blank"><font color="#000000"><%= mid(rs("title"),1,32)%></font></a> </td>
<%if i mod 2 <>0 then
end if
if i mod 2 =0 then
Response.Write "</TR><TR>"
end if
rs.MoveNext
i=i+1
Loop
rs.close%>
我这么写怎么不能输出啊?
实在没分了,希望高手指点一下,在线等!
500错误,不行! 展开
i=-1
do while not rs.eof
%>
<td onMouseOver="this.style.backgroundColor='#EEF7FF';return true;" onMouseOut="this.style.backgroundColor='#ffffff';" width="25" height="18"><img src="images/icon_new.gif" width="18" height="15"></td>
<td width="279" height="18"><a href="shownews.asp?id=<%=rs("id") %>" target="_blank"><font color="#000000"><%= mid(rs("title"),1,32)%></font></a> </td>
<%if i mod 2 <>0 then
end if
if i mod 2 =0 then
Response.Write "</TR><TR>"
end if
rs.MoveNext
i=i+1
Loop
rs.close%>
我这么写怎么不能输出啊?
实在没分了,希望高手指点一下,在线等!
500错误,不行! 展开
3个回答
展开全部
我帮你改了下.你用下面这个代码吧.
<%
set rs=server.createobject("adodb.recordset")
sql ="select top 20 * from news where BigClassName='测试新闻' order by AddDate desc"
rs.open sql,conn,1,1
%>
<table border="0" cellpadding="0" style="border-collapse: collapse" width="800" height="100%" >
<%
for i=1 to rs.recordCount
if (i mod 2 =1) then
response.write "<tr >"
end if
%>
<td onMouseOver="this.style.backgroundColor='#EEF7FF';return true;" onMouseOut="this.style.backgroundColor='#ffffff';" width="25" height="18"><img src="images/icon_new.gif" width="18" height="15"></td>
<td width="279" height="18"><a href="shownews.asp?id=<%=rs("id") %>" target="_blank"><font color="#000000"><%= rs("title")%></font></a> </td>
<%if (i mod 2 = 0) then
response.write "</tr>"
end if
rs.movenext
next
rs.close
%>
</table>
<%
set rs=server.createobject("adodb.recordset")
sql ="select top 20 * from news where BigClassName='测试新闻' order by AddDate desc"
rs.open sql,conn,1,1
%>
<table border="0" cellpadding="0" style="border-collapse: collapse" width="800" height="100%" >
<%
for i=1 to rs.recordCount
if (i mod 2 =1) then
response.write "<tr >"
end if
%>
<td onMouseOver="this.style.backgroundColor='#EEF7FF';return true;" onMouseOut="this.style.backgroundColor='#ffffff';" width="25" height="18"><img src="images/icon_new.gif" width="18" height="15"></td>
<td width="279" height="18"><a href="shownews.asp?id=<%=rs("id") %>" target="_blank"><font color="#000000"><%= rs("title")%></font></a> </td>
<%if (i mod 2 = 0) then
response.write "</tr>"
end if
rs.movenext
next
rs.close
%>
</table>
展开全部
试试这个代码,如果记录集有问题,可以发现错误:
<%
set rs=server.createobject("adodb.recordset")
err.clear
on error resume next
rs.open "select top 20 * from news where BigClassName='测试新闻' order by AddDate desc ",conn,1,1
if err.number <> 0 then
response.write "打开记录集错误:" & err.Description
set rs = nothing
response.end
end if
if rs.recordcount<=0 then
response.write "无记录"
rs.close
set rs = nothing
response.end
end if
i=0
rs.movefirst
%>
<table border="0" cellpadding="0" width="800">
<tr>
<%
while not rs.eof
i=i+1
%>
<td onMouseOver="this.style.backgroundColor='#EEF7FF';return true;" onMouseOut="this.style.backgroundColor='#ffffff';" width="25" height="18"><img src="images/icon_new.gif" width="18" height="15"></td>
<td width="279" height="18"><a href="shownews.asp?id=<%=rs("id") %>" target="_blank"><font color="#000000"><%= mid(rs("title"),1,32)%></font></a></td>
<%
if i mod 2 =0 then
Response.Write "</TR><TR>"
end if
rs.MoveNext
wend
rs.close
if i mod 2 =1 then
response.write "<td></td><td></td></tr>"
end if
%>
</table>
<%
set rs=server.createobject("adodb.recordset")
err.clear
on error resume next
rs.open "select top 20 * from news where BigClassName='测试新闻' order by AddDate desc ",conn,1,1
if err.number <> 0 then
response.write "打开记录集错误:" & err.Description
set rs = nothing
response.end
end if
if rs.recordcount<=0 then
response.write "无记录"
rs.close
set rs = nothing
response.end
end if
i=0
rs.movefirst
%>
<table border="0" cellpadding="0" width="800">
<tr>
<%
while not rs.eof
i=i+1
%>
<td onMouseOver="this.style.backgroundColor='#EEF7FF';return true;" onMouseOut="this.style.backgroundColor='#ffffff';" width="25" height="18"><img src="images/icon_new.gif" width="18" height="15"></td>
<td width="279" height="18"><a href="shownews.asp?id=<%=rs("id") %>" target="_blank"><font color="#000000"><%= mid(rs("title"),1,32)%></font></a></td>
<%
if i mod 2 =0 then
Response.Write "</TR><TR>"
end if
rs.MoveNext
wend
rs.close
if i mod 2 =1 then
response.write "<td></td><td></td></tr>"
end if
%>
</table>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在do循环前加上判断
IF Rs.Recordcount=0 Then
Response.Write"没有记录"
Response.End
End IF
你没有加判断有可能没有值的时候就会出错
IF Rs.Recordcount=0 Then
Response.Write"没有记录"
Response.End
End IF
你没有加判断有可能没有值的时候就会出错
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询