#12004/12/15 15:21:16
已经看过置顶的那个帖子了,但这个和楼主所说的
“在rs.open sql,conn,3,3语句之前使用了rs.close关闭了rs对象
解决方法:去掉之前的rs.close ”
不一样,请看下边的代码<HTML>
<HEAD>
<TITLE>无标题文档</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<%
dim rec
dim intPage
dim strQuote
dim strScriptName
'dim booktype
dim sql
strQuote=Chr(34) 'The double quote character
'以下为分页显示所有书的信息
'Set cn=Server.CreateObject("ADODB.Connection")
'cn.Open "dsn=regweb;uid=rwadmin;pwd=rwadmin"
set rs=server.CreateObject("adodb.recordset")
sql="select Book_No,Book_Name,Book_Pub,Book_Price,Book_Store from ebook where Book_Type="
sql=sql&"'"&booktype&"'"
if (flag="1") then
sql=sql&" and "&selecttype&" like '%"&key&"%'"
end if
rs.PageSize=10
if Request.QueryString("page")="" then
intPage=1
else
intPage=CInt(Request.QueryString("page"))
if (intPage<1) then
intPage=1
else
if (intPage > rs.PageCount) then
intPage=rs.PageCount
end if
end if
end if
'if not rs.EOF then
'rs.AbsolutePage=intPage
'else
' intPage=0
'end if
%>
<%
for i=1 to rs.PageSize
if rs.EOF then
exit for
end if
%>
<%
Dim rssyjs,tc,page,allpage,pno
'Set rsDepartment = Server.CreateObject("ADODB.Recordset")
'rsDepartment.Open "Department", objConn, adOpenKeyset,adLockPessimistic, adCmdTable
page=request.querystring("page")'获取超连接?后面的页数
rs.pagesize=10 '这里我们设定每页显示的记录数是10个
allpage=rs.pagecount '这是统计一下记录总共能分多少页
if isempty(page) or cint(page)<1 then
page=1
elseif cint(page)>allpage then
page = allpage
end if
rs.absolutepage=page '这一句是指定当前页为request.querystring("page")接收到的页数
tc=rs.pagesize
If Not rs.EOF Then
%>
<TABLE BORDER="0" WIDTH="80%" CELLPADDING="2" CELLSPACING="4" ALIGN="center">
<%
while not rs.eof and tc>0 '循环条件:指针不是指向记录最后一条之后,和记录条数大于0则循环开始!
rsname = rs("name")
rsdate = rs("date")
id=rs("id")
%>
<TR> <TD WIDTH="319">
<A HREF="syjs_blank.asp?id=<%=id%>"TARGET="_blank"><%=rsname%></A>
</TD>
<TD WIDTH="110"><%=rsdate%></TD></TR>
<% rs.movenext '这是ASP内置的游标,表示移动到此记录的下一条这不就实现了循环了吗?
tc=tc-1 '没循环一次记录条数就减去1,直到有一次记录条数为0了,呵呵,循环也就结束了!
wend '循环语句结束 %> </TABLE>
<TABLE WIDTH="81%" BORDER="0" ALIGN="center"> <R> <TD>
<DIV ALIGN="center"><FONT COLOR="#FF0000"><BR>
<%
strScriptName=Request.ServerVariables("SCRIPT_NAME")
%> <FONT COLOR="#999999">
<%
if (intPage=1) or (intPage=0) then
Response.Write " <span>首页</span>"
else
Response.Write " <a href=" & strQuote & strScriptName &_
"?flag="&Request.QueryString("flag")&"&booktype="&booktype&"&page=1"&strQuote&">首页</a>"
end if
%> </FONT>
<FONT COLOR="#999999">
<%if (intPage=1) or (intPage=0) then
Response.Write " <span>上一页</span>"
else
Response.Write " <a href=" & strQuote & strScriptName &_
"?flag="&Request.QueryString("flag")&"&booktype="&booktype&"&page="&intPage-1&strQuote&">上一页</a>"
end if
%> </FONT>
<FONT COLOR="#999999">
<%
if intPage=rec.PageCount then
Response.Write " <span>下一页</span>"
else
Response.Write " <a href=" & strQuote & strScriptName &_
"?flag="&Request.QueryString("flag")&"&booktype="&booktype&"&page="&intPage+1&strQuote&">下一页</a>"
end if
%> </FONT>
<FONT COLOR="#999999">
<%
if intPage=rec.PageCount then
Response.Write " <span>尾页</span>"
else
Response.Write " <a href=" & strQuote & strScriptName &_
"?flag="&Request.QueryString("flag")&"&booktype="&booktype&"&page="&rec.PageCount &strQuote&">尾页</a>"
end if
%> </FONT> 第<FONT COLOR="#CC0000"><%=intPage%>/<%=rec.PageCount%></FONT>页<FONT COLOR="#CC0000"><% end if %>
<% next %></FONT></FONT>
</DIV>
</TD></TR> </TABLE>
</BODY>
</HTML>
其中红色部分是显示的错误行
请各位来帮忙指点以下
编辑历史:[此帖最近一次被 leihen777 编辑过(编辑时间:2004-12-15 15:31:44)]