分页问题,急!

liuchenghy 2006-02-23 04:34:28
前面发过贴子,没得到答案,再问各位,我把代码简化了一下,大家再帮我看看,点击分页后得出的结果为全部,没按条件分页!
<html>
<head>
<title>利用ADO分页</title>
</head>
<body>
<!-- METADATA TYPE="typelib" File="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<%
Dim cn,rs,sh_name
Dim iPage

Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "Driver={SQL Server};Server=cd;Database=ASPTest;" & _
"UID=sa;PWD=sa"
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.PageSize = 1 '这个值读者在使用时可根据需要设置
sh_name=trim(Request("sh_name"))
rs.Open "SELECT * FROM Chapter8 where 名称 like '%"&sh_name&"%'",cn,adOpenStatic,adLockReadOnly

If Len(Request("page")) = 0 Then
iPage = 1
Else
iPage = Request("page")
End If

rs.AbsolutePage = iPage
%>
<p align="center">图书信息第<% =iPage%>页</p>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="646" align="center">
<form name="1">
<input name="sh_name" type="text"/>
<input type="submit" name="Button1" value="查 询" id="Button1" />
</form>
<tr>
<td width="33">编号</td>
<td width="98">名称</td>
<td width="37">作者</td>
<td width="56">类别</td>
<td width="135">出版社</td>
<td width="69">出版日期</td>
<td width="33">价格</td>
<td width="39">页数</td>
</tr>
</tr>
<%
For i =1 To rs.PageSize
If Not rs.Eof Then
%>
<tr>
<td width="33"><%=rs(0)%> </td>
<td width="98"><%=rs(1)%> </td>
<td width="37"><%=rs(2)%> </td>
<td width="56"><%=rs(3)%> </td>
<td width="135"><%=rs(4)%> </td>
<td width="69"><%=rs(5)%> </td>
<td width="33"><%=rs(6)%> </td>
<td width="39"><%=rs(7)%> </td>
</tr>
<%
End If
If Not rs.Eof Then rs.MoveNext
Next
%>
</table>
<p align="center">
<% If CInt(iPage) = 1 Then %>
第一页|上一页|
<% Else %>
<a href="08_07.asp?page=1">第一页</a>|
<a href="08_07.asp?page=<% = iPage - 1 %>">上一页</a>|
<% End If %>
<% If CInt(iPage) = CInt(rs.PageCount) Then %>
下一页| 最后一页
<% Else %>
<a href="08_07.asp?page=<% = iPage + 1 %>">下一页</a>|
<a href="08_07.asp?page=<% = rs.PageCount %>">最后一页</a>
<% End If %>
<%
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
%>
</body>
</html>
...全文
131 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
任亚军 2006-02-24
  • 打赏
  • 举报
回复
buxing
liuchenghy 2006-02-23
  • 打赏
  • 举报
回复
有没有办法可以让他重新执行SQL而是用上面的结果来分页?这样就可以避免再读数据库?可行吗?
jingxiaoping 2006-02-23
  • 打赏
  • 举报
回复
分页的话,数据多的时候,只要你的程序写的非常得体,也不会出现速度很慢的情况。
jingxiaoping 2006-02-23
  • 打赏
  • 举报
回复
rs.PageSize = 1 '这个值读者在使用时可根据需要设置

放到rs.open 下面试试,再一个你的rs.pagesize设多些。
liuchenghy 2006-02-23
  • 打赏
  • 举报
回复
可以了,谢谢,那是不是每点击一次分页都得执行一上SQL?如果数据多的话这样会不会很慢?
任亚军 2006-02-23
  • 打赏
  • 举报
回复
<html>
<head>
<title>利用ADO分页</title>
</head>
<body>
<!-- METADATA TYPE="typelib" File="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<%
Dim cn,rs,sh_name
Dim iPage

Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "Driver={SQL Server};Server=cd;Database=ASPTest;" & _
"UID=sa;PWD=sa"
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.PageSize = 1 '这个值读者在使用时可根据需要设置
sh_name=trim(Request("sh_name"))
rs.Open "SELECT * FROM Chapter8 where 名称 like '%"&sh_name&"%'",cn,adOpenStatic,adLockReadOnly

If Len(Request("page")) = 0 Then
iPage = 1
Else
iPage = Request("page")
End If

rs.AbsolutePage = iPage
%>
<p align="center">图书信息第<% =iPage%>页</p>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="646" align="center">
<form name="1">
<input name="sh_name" type="text"/>
<input type="submit" name="Button1" value="查 询" id="Button1" />
</form>
<tr>
<td width="33">编号</td>
<td width="98">名称</td>
<td width="37">作者</td>
<td width="56">类别</td>
<td width="135">出版社</td>
<td width="69">出版日期</td>
<td width="33">价格</td>
<td width="39">页数</td>
</tr>
</tr>
<%
For i =1 To rs.PageSize
If Not rs.Eof Then
%>
<tr>
<td width="33"><%=rs(0)%> </td>
<td width="98"><%=rs(1)%> </td>
<td width="37"><%=rs(2)%> </td>
<td width="56"><%=rs(3)%> </td>
<td width="135"><%=rs(4)%> </td>
<td width="69"><%=rs(5)%> </td>
<td width="33"><%=rs(6)%> </td>
<td width="39"><%=rs(7)%> </td>
</tr>
<%
End If
If Not rs.Eof Then rs.MoveNext
Next
%>
</table>
<p align="center">
<% If CInt(iPage) = 1 Then %>
第一页|上一页|
<% Else %>
<a href="08_07.asp?sh_name=<%=sh_name%>&page=1">第一页</a>|
<a href="08_07.asp?sh_name=<%=sh_name%>&page=<% = iPage - 1 %>">上一页</a>|
<% End If %>
<% If CInt(iPage) = CInt(rs.PageCount) Then %>
下一页| 最后一页
<% Else %>
<a href="08_07.asp?sh_name=<%=sh_name%>&page=<% = iPage + 1 %>">下一页</a>|
<a href="08_07.asp?sh_name=<%=sh_name%>&page=<% = rs.PageCount %>">最后一页</a>
<% End If %>
<%
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
%>
</body>
</html>
liuchenghy 2006-02-23
  • 打赏
  • 举报
回复
是哪里让让结果重新执行了,而没保留按条件查询出来的结果?

28,391

社区成员

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

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