两个文件的源码如下: ////////////////////////// a.asp ////////////<html> <head> <title>利用ADO分页</title> </head> <body> <% Dim cn,rs Dim iPage
Set cn = Server.CreateObject("ADODB.Connection") cn.Open "Driver={SQL Server};Server=zhuoming;Database=ASPTest;" & _ "UID=sa;PWD=19821204" Set rs = Server.CreateObject("ADODB.RecordSet") Set rs.ActiveConnection = Cn rs.PageSize = 2 '这个值读者在使用时可根据需要设置 rs.CursorType = 3 rs.Open "SELECT * FROM information"
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"> <tr>
<td width="20%">编号</td> <td width="20%">名称</td> <td width="20%">作者</td> <td width="20%">价格</td> <td width="20%">出版日期</td> </tr> </tr> <% For i =1 To rs.PageSize If Not rs.Eof Then %> <tr> <td width="20%"><%=rs(0)%> </td> <td width="20%"><%=rs(1)%> </td> <td width="20%"><%=rs(2)%> </td> <td width="20%"><%=rs(3)%> </td> <td width="20%"><%=rs(4)%> </td> </tr> <% End If If Not rs.Eof Then rs.MoveNext Next %> </table> <p align="center"> <% If CInt(iPage) = 1 Then %> 第一页|上一页| <% Else %> <a href="a.asp?page=1">第一页</a>| <a href="a.asp?page=<% = iPage - 1 %>">上一页</a>| <% End If %> <% If CInt(iPage) = CInt(rs.PageCount) Then %> 下一页| 最后一页 <% Else %> <a href="a.asp?page=<% = iPage + 1 %>">下一页</a>| <a href="a.asp?page=<% = rs.PageCount %>">最后一页</a> <% End If %> <% rs.Close Set rs = Nothing cn.Close Set cn = Nothing %> <form name="aform" method="post" action="b.asp"> 排列功能:<p> 请填入列名:<input name="lieming" type="text" size="10"> 升序<input name="pailie" type="radio" value="sheng" checked> 降序<input name="pailie" type="radio" value="jian"> <input name="submit2" type="submit" id="submit2" value="确定"> <input name="reset2" type="reset" id="reset2" value="取消"> </form> </body> </html> ///////////////////////////////////////////// b.asp: ///////////////////////// <html> <head> <title>利用ADO分页</title> </head> <body> <% Dim cn,rs Dim iPage dim lieming Set cn = Server.CreateObject("ADODB.Connection") cn.Open "Driver={SQL Server};Server=zhuoming;Database=ASPTest;" & _ "UID=sa;PWD=19821204" Set rs = Server.CreateObject("ADODB.RecordSet") Set rs.ActiveConnection = Cn rs.PageSize = 2 rs.CursorType = 3 lieming=request.form("lieming") pailie=request.form("pailie")
if pailie="sheng" then rs.Open "SELECT * FROM information order by '"&lieming&"' asc" elseif pailie="jian" then rs.Open "SELECT * FROM information order by '"&lieming&"' desc" end if 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"> <tr> <td width="20%">编号</td> <td width="20%">名称</td> <td width="20%">作者</td> <td width="20%">价格</td> <td width="20%">出版日期</td> </tr> </tr> <% For i =1 To rs.PageSize If Not rs.Eof Then %> <tr> <td width="20%"><%=rs(0)%> </td> <td width="20%"><%=rs(1)%> </td> <td width="20%"><%=rs(2)%> </td> <td width="20%"><%=rs(3)%> </td> <td width="20%"><%=rs(4)%> </td> </tr> <% End If If Not rs.Eof Then rs.MoveNext Next %> </table> <p align="center"> <% If CInt(iPage) = 1 Then %> 第一页|上一页| <% Else %> <a href="b.asp?page=1">第一页</a>| <a href="b.asp?page=<% = iPage - 1 %>">上一页</a>| <% End If %> <% If CInt(iPage) = CInt(rs.PageCount) Then %> 下一页| 最后一页 <% Else %> <a href="b.asp?page=<% = iPage + 1 %>">下一页</a>| <a href="b.asp?page=<% = rs.PageCount %>">最后一页</a> <% End If %> <% rs.Close Set rs = Nothing cn.Close Set cn = Nothing %> </body> </html> 第一页可以正确显示,第二页就不行了,错误如下:
ADODB.Recordset 错误 '800a0e78'
对象关闭时,操作不被允许。
/b.asp,行30 望各位高手百忙中抽空看看,小弟感激不尽,先谢谢啦