数据库记录分页问题!急急急急急急急急急急急急

RiskyWei 2003-03-08 04:36:52
在写分页代码时出现了一个奇怪的问题,那就是给当前页赋值时老是出错,非常奇怪
谁能看出是哪个地方错了吗?代码如下:
<%@ language=vbscript%>
<%
Option explicit
Response.Expires=0
%>
<%'!-- #include file="inc_files\dbinit.inc--%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="charset=gb2312">
<TITLE></TITLE>
</HEAD>
<%
Dim Conn,connString,sqlString,Rs,CurrentRecords,intPageNo
const intPageSize=10
sqlString="Select BookID,BookName,Author,PublisherID,Price,PublishDate from BookInfo"

Set Conn = server.CreateObject("ADODB.Connection")
connString="provider=sqloledb;UId=sa;pwd=;database=package;datasource=wkm"
Conn.Open connString
Set Rs=server.CreateObject("ADODB.RecordSet")
'Rs.CursorType =adOpenStatic
Rs.CacheSize=10
Rs.Open sqlString,Conn,1,3
Rs.PageSize=intPageSize

intPageNo=Request.QueryString("whichPage")
if intPageNo="" then
intPageNo=1
end if
Rs.AbsolutePage=intPageNo '问题就出现在这里!!!!!!!!!!

CurrentRecords = Rs.fields.count-1
recNum=0
%>
<BODY bgColor=ivory >
......
以下不再写了(下面的代码没有问题,已经调试通过)

--------------------------------------------------------------
浏览器对语句Rs.AbsolutePage=intPageNo 提示出错如下
错误类型:
ADODB.Recordset (0x800A0CB3)
/happytest/querybkresult.asp, 第 30 行

而且我直接把1赋给Rs.AbsolutePage都有错:Rs.Absolutepage=1 !所以肯定不是这句的问题了,好像是其他地方还要对数据库的一些参数进行设置,分页操作都需要做那些配置呀?
好困惑!

(0x800A0CB3)是什么类型的错误?



请大家指点,谢谢了
...全文
97 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2003-03-08
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?contentid=28001860
孟子E章 2003-03-08
  • 打赏
  • 举报
回复
800a0cb3错误一般是:对象或提供者不能执行所需的操作,因此很有可能与你的ado版本有关系
孟子E章 2003-03-08
  • 打赏
  • 举报
回复
估计两个机器的ado版本不同,建议都安装ado2.7
可以到msdn免费下载,还可以下载ado版本检测工具
RiskyWei 2003-03-08
  • 打赏
  • 举报
回复
自然有了。
我去掉这句后一切正常,显示最开头的10条记录。但是一加上这句就出错!而且同样是这句,我在另一个程序一点问题都没有!而且我当时用的游标还是最开始的 Rs.open sqlString,Conn,1,3
为什么一样的语句在这个程序里就不行呢?!!!!!!!!!!!!!!
气死我了!
月光易水 2003-03-08
  • 打赏
  • 举报
回复
1. 读取显示数据,Rs.open sqlString,Conn,1,1即可
2. 表中是否有数据?

:_)
RiskyWei 2003-03-08
  • 打赏
  • 举报
回复
奇怪的是我在另一个程序里用 Rs.open sqlString,Conn,1,3就可以!而在这个里一直报错!我都给弄晕了!分个页并不是很烦的事情,为什么老是出错呢!?
希望大家帮帮忙!谢了!
孟子E章 2003-03-08
  • 打赏
  • 举报
回复
现成的例子
<%

On Error Resume Next

Dim strCZ,strLB,strFX

Dim strConnString,rs,sql,cn
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("hsfc.mdb")
strCZ = Request.QueryString("cz")
strLB = Request.QueryString("lb")
strFX = Request.QueryString("fx")

sql = "SELECT TOP "& Trim(Request.QueryString("new")) &" * FROM fwxx WHERE [rent/sale] = '"& strCZ &"'"

If Trim(strLB) <> "0" Then sql = sql & " AND purpose='" & strLB & "'"
If Trim(strFX) <> "0" Then sql = sql & " AND house_configuration='" & strFX & "'"
sql = sql & " ORDER BY ID DESC"

Response.write sql
Set rs = Server.CreateObject("ADODB.RecordSet")
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open strConnString
rs.Open sql,cn,1,3

'Response.Write rs.RecordCount

Response.Write "<table border=""0"" width=""98%"" cellspacing=""1"" cellpadding=""3"" bgcolor=""gray"">"
Response.Write "<tr bgcolor=""#D8D8D8"" style='font-weight:bold' align='center'><td width='50%'>出租、出售</td><td width='18%'>姓名</td><td width='10%'>地点</td><td width='22%'>层数</td></tr>" & vbCrLf

Dim pageField,intpage,i,nItemPerPage
intpage = CInt(Request.QueryString("page"))
If intpage = 0 Then intpage = 1
pageField = Int((intpage-1)/10)
nItemPerPage = Trim(Request.QueryString("npp"))

If nItemPerPage = "" Then
nItemPerPage = 10
Else
nItemPerPage = CInt(nItemPerPage)
End If

If rs.RecordCount > 0 Then

rs.PageSize = nItemPerPage
rs.Move pageField * 10 * nItemPerPage + (intpage - pageField * 10-1) * nItemPerPage

For I = 1 To nItemPerPage
If rs.Eof Then
Exit For
End If
If I Mod 2 = 1 Then
Response.Write "<tr bgcolor=""#FFFFFF"">"
Else
Response.Write "<tr bgcolor=""#EEEEEE"">"
End If

Response.Write "<td><a href=""detail.asp?id=" & rs("ID") & """>" & rs("rent/sale") & "</a></td>"
Response.Write "<td>" & rs("name") & "</td>"
Response.Write "<td>" & rs("address") & "</td>"
Response.Write "<td>" & rs("floor") & "</td>"
Response.Write "</tr>" & vbCrLf
rs.MoveNext
Next
Response.Write "<tr bgcolor=""#FFFFFF""><td colspan='4' align=""center"" height=""26"">"
Response.Write "<font style = 'color:#000099; font-size:9pt'>第<b>" & intPage & "/" & rs.PageCount & "</b>页 每页<b>" & nItemPerPage & "</b>条 共<b>" & rs.RecordCount & "</b>条记录 转到:</font> "
If pageField > 0 Then
Response.Write "<a href=search.asp?cz=" & strCZ & "&lb=" & strLB & "&fx=" & strFX & "&npp=" & CStr(nItemPerPage) & "&page=" & ((pageField-1)*10+1) & "><font size=3>上十页</font></a> "
End If
For i = pageField*10+1 To pageField*10+10
If i <= rs.PageCount Then
If i = intpage Then
response.write "<font size=4 color=red>" & i & "</font> "
Else
Response.Write "<a href=search.asp?cz=" & strCZ & "&lb=" & strLB & "&fx=" & strFX & "&npp=" & CStr(nItemPerPage) & "&page=" & i & "><font size=4>" & i & "</font></a> "
End If
End If
Next
If Int(rs.PageCount/10) > pagefield Then
Response.Write "<a href=search.asp??cz=" & strCZ & "&lb=" & strLB & "&fx=" & strFX & "&npp=" & CStr(nItemPerPage) & "&page=" & (PageField+1)*10+1 & "><font size=3>下十页</font></a>"
End If
Response.Write "</td></tr>" & vbCrLf
Else
Response.Write "<tr bgcolor=""#FFFFFF""><td colspan=3 align=""center"" height=""26"">没有符合条件的记录。</td></tr>" '没有记录
End If
Response.Write "</table>"
rs.Close
Set rs = Nothing



%>

<form name="form1" method="GET" action="search.asp">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr> <br>
<td colspan="2" height="36">
<input type="radio" name="cz" value="出租" checked>
出 租
<input type="radio" name="cz" value="出售">
出 售<br>
<input type="radio" name="cz" value="求租">
求 租
<input type="radio" name="cz" value="求购">
求 购
<br>
</td>
</tr>
<tr>
<td width="41">
<div align="center">类别:</div></td>
<td width="112">
<select name="lb" size="1">
<option value="0">--全 部--</option>
<option value="住宅">住宅</option>
<option value="办公">办公</option>
<option value="商业">商业</option>
</select>
</td>
</tr>
<tr>
<td width="41">
<div align="center">房型:</div>
</td>
<td width="112">
<select name="fx" size="1">
<option value="0">--全 部--</option>
<option value="一户一室">一户一室</option>
<option value="一户二室">一户二室</option>
<option value="一户三室">一户三室</option>
<option value="一室一厅">一室一厅</option>
<option value="二室一厅">二室一厅</option>
<option value="三室一厅">三室一厅</option>
<option value="四室一厅">四室一厅</option>
<option value="一室二厅">一室二厅</option>
<option value="二室二厅">二室二厅</option>
<option value="三室二厅">三室二厅</option>
<option value="最新结构">最新结构</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<div align="center"><br>
最新5条:<input name="new" value="5">
<input type=submit value="【搜索】">
</div>
</td>
</tr>
</table>
</form>
cqs76 2003-03-08
  • 打赏
  • 举报
回复
试试用键盘指针,2
RiskyWei 2003-03-08
  • 打赏
  • 举报
回复
没有用!试过了,问题依旧!
possible_Y 2003-03-08
  • 打赏
  • 举报
回复
Rs.Open sqlString,Conn,3,3
春哥视角 2003-03-08
  • 打赏
  • 举报
回复
Rs.Open sqlString,Conn,3,3

游标问题
孟子E章 2003-03-08
  • 打赏
  • 举报
回复
Rs.Open sqlString,Conn,3,3

28,391

社区成员

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

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