请教高手关于asp分页浏览的问题,我不知道我的程序错在那里?

aming 2002-07-11 01:23:32
test.asp
<!--#include file="Rs2Tab.asp" -->
<html>

<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#FFFFFF">
<b>
<b>
<b>
<p align="center"><font size="10">asp page brows</font></p>
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "newphs","sa",""
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn
sql="select * from raiu_info"
response.write sql
cmd.CommandText = sql
Set rs= cmd.Execute
'RsToTable1 rs,""
'调用showlist来分页显示结果
showlist rs
conn.close

%>

<p>  </p>

<p>  </p>
</body>
</html>

以下是rs2tab.asp 的内容

<%
Sub showlist(rs)

'显示标题===================================================================================
Response.Write "<TABLE BORDER=0 width=800>"
Response.Write "<TR BGCOLOR=#C1EBFF>"
For i=0 to rs.Fields.Count-1
Response.WRITE "<TD bgcolor='#0080C0' height='22'><font color='#ffffff'>" & rs.Fields(i).Name & "</font></TD>"
Next
Response.Write "</TR>"

'如果数据库中没有数据的情况
if rs.eof and rs.bof then str="此留言簿还没有一个留言!" end if
'分页设置----------------------------------------------------------------------------------
if str="" then
rs.PageSize=5
pages=rs.pagecount
records=rs.recordcount
response.write records
currentpage=request("currentpage")
else
currentpage=1
records=0
pages=1
end if
if currentpage="" or currentpage<"1" then currentpage="1"
currentpage=cint(currentpage)
if currentpage>pages then
currentpage=pages
' response.write pages
rs.absolutepage=pages
end if
'分页设置-----------------------------------------------------------------------------------
'显示具体记录===============================================================================
linenumber=rs.pagesize
LINE=1
DO WHILE (NOT RS.EOF) AND (Line<=linenumber)
RESPONSE.WRITE "<TR bgcolor='#e7f3ff' align='center'>"
For i=0 to rs.Fields.Count-1
RESPONSE.WRITE "<td width='"&tdwidth&"' style='border-right-style: solid; border-right-width: 1; border-top-style: solid; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1' bordercolor='#FFFFFF' height='12'><font size='3' color='#333399'>"&RS.FIELDS(I).VALUE&"</font></td>"
NEXT
RESPONSE.WRITE "</TR>"
RS.MOVENEXT
LINE=LINE+1
LOOP

RESPONSE.WRITE "</TABLE>"

End Sub
%>
<html>
<head>
</head>
<body>
</body>
</html>


如果把rs.absolutepage=pages语句去掉,则cs_test.asp可以执行显示出第一页的结果,但如果加上去就会提示该语句出错,把rs.absolutepage=pages改成rs.absolutepage=1仍然出错,是否我该属性用法错了.如果把pages和recordcount打印出来,就会发现他们的值都是-1,而事实上我所查询的表记录不止50条.那位大虾告诉我那里错了!
...全文
31 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
aming 2002-07-11
  • 打赏
  • 举报
回复
是打开记录集方法错误。
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn
sql="select * from raiu_info"
cmd.CommandText = sql
Set rs= cmd.Execute
更换成
set rs=server.createobject("adodb.recordset")
sql="select * from raiu_info"
rs.open sql,conn,1,1

后就可以用了,但是有些查询(带参数的存储过程查询
如 exec sp_lp_spare 1,'',0 这种格式
仍然会出现错误
仍然是
把rs.absolutepage=pages语句去掉,则cs_test.asp可以执行显示出第一页的结果,但如果加上去就会提示该语句出错,把rs.absolutepage=pages改成.如果把pages和recordcount打印出来,就会发现他们的值都是-1,而事实上当然不是-1
请教各位大虾,对这种情况是否rs.open应该改写一下
aming 2002-07-11
  • 打赏
  • 举报
回复
to WUNEN(吴灵) :
为什么不用循环来把rs各个记录的字段名(中文别名可以在sql语句中)和值写出来?
aming 2002-07-11
  • 打赏
  • 举报
回复
Set rs= cmd.Execute 是没有错的只要把showlist替换成没有分页的子程序就可以很好的显示出来.
skyarrow 2002-07-11
  • 打赏
  • 举报
回复
打开记录集方法错误。换其它的试试。
skyarrow 2002-07-11
  • 打赏
  • 举报
回复
肯定是打开纪录集的方法错误
WUNEN 2002-07-11
  • 打赏
  • 举报
回复
下面是一个完整的分页网页,只需略加修改就行,
<%
t3=trim(request("t3")) '其他条件
if t3="" then
response.write "<font color=red size=h3><center>"&"没有找到符合条件的记录!请重新输入关键字再查询!"&"</center></font>"
response.end
end if
set rs=server.createobject("adodb.recordset")

t5="%"&t3&"%"
sql="select * from tele_dh where demo like '"&t5&"'"

rs.open sql,session("xx_conn"),1,1
if rs.bof and rs.eof then
response.write "<font color=red size=h3><center>"&"没有找到您要找的数据!!"&"</center></font>"
response.end
end if
'=====================分页======================
if not( RS.BOF and RS.EOF) then
RS.PageSize =2
mPG=cint(Request("pg"))
if mPG=0 then
mPG=1
end if %>
<%if rs.recordcount>2 then%><%if mPG>1 then%>【 <a href="h_1.asp?pg=<%=(mPG-1)%>&t3=<%=t3%>">上一页</a>】【<a href="h_1.asp?pg=1&t3=<%=t3%>">一页</a>】
<%else%> 【上一页】 【一页】 <%end if%>
<%if mPG<Rs.PageCount then%>【 <a href="h_1.asp?pg=<%=(mPG+1)%>&t3=<%=t3%>">下一页</a> 】【<a href="h_1.asp?pg=<%=rs.pagecount%>&t3=<%=t3%>">或一页</a>】
<%else%> 【下一页 】【或一页】<%end if%> <%end if %>
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolorlight="#000000" bordercolordark="#FFFFFF" bgcolor="#9999FF" align="center" height="46">
<tr>
<td width="11%" height="32">
<div align="center"> 共<%=Rs.PageCount%>页  </div>
</td>
<td colspan="4" height="32">
<center>
 查询结果如下
</center>
</td>
<td width="23%" height="32">
<center>
第<%=mPG%>页 共<%=rs.recordcount%>笔
</center>
</td>
</tr>
<tr>
<td width="11%" height="29">
<center>
姓名
</center>
</td>
<td width="12%" height="29">
<center>
职务
</center>
</td>
<td width="23%" height="29">
<center>
单位部门
</center>
</td>
<td width="20%" height="29">
<center>
办公室电话
</center>
</td>
<td width="11%" height="29">
<center>
住宅电话
</center>
</td>
<td width="23%" height="29">
<center>
手机
</center>
</td>
</tr>
<%
RS.AbsolutePage = mPG
RowCount = rs.PageSize
j=(mpg-1) * rowcount
Do While Not RS.EOF and rowcount > 0
j=j+1
%>
<tr>
<td width="11%" height="29" bgcolor="#FFFFFF">
<center>
<%=rs(2)%>  
</center>
</td>
<td width="12%" height="29" bgcolor="#FFFFFF">
<center>
<%=rs(1)%>  
</center>
</td>
<td width="23%" height="29" bgcolor="#FFFFFF">
<center>
<%=rs(0)%>  
</center>
</td>
<td width="20%" height="29" bgcolor="#FFFFFF">
<center>
<%=rs(3)%>  
</center>
</td>
<td width="11%" height="29" bgcolor="#FFFFFF">
<center>
<%=rs(4)%>  
</center>
</td>
<td width="23%" height="29" bgcolor="#FFFFFF">
<center>
<%=RS(5)%>  
</center>
</td>
</tr>
<% RowCount = RowCount - 1
RS.MoveNext
Loop
end if
%>
MAGICSLIAO 2002-07-11
  • 打赏
  • 举报
回复
If Not Rs.Eof Then
Rs.absolutepages=pages
End if
cmsoft 2002-07-11
  • 打赏
  • 举报
回复
用这个rs.open sql,conn,1,3试试打开记录集

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧