日期:2014-05-17  浏览次数:20903 次

ASP分页功能数据库里表没有数据的时候 页面就出错了 请教下要怎么改
<%
  dim cnstr,epage,i,id 
  id=request.QueryString("id")
  cnstr = "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.MapPath("./sb.mdb") 
  dim rs
  set cn = server.CreateObject("adodb.connection")
  cn.Open cnstr
  sql = "select * from shenbao where U_ID="&id&" and S_Zt='已审核' order by S_time desc "
  set rs = server.createobject("adodb.recordset")
  rs.open sql,cn,3
  rs.pagesize=20
  '设置每页记录数
  if request("page")<>"" then
  epage=cint(request("page"))
  '取当前的页数
  if epage<1 then epage=1
  '若当前页数小于1则置为1
  if epage>rs.pagecount then epage=rs.pagecount
  '若当前页数大于最大页数值则置为最大页数
  else
  epage=1
  '否则页数为默认值1
  end if
  rs.absolutepage=epage
  '记录定位到当前页
  for i=0 to rs.pagesize-1
  '循环显示本页记录
  if rs.bof or rs.eof then exit for 
  '若已经到记录末尾或没有数据则退出循环
response.Write "<tr>"
response.write "<td align='left' width='40%' >&nbsp;&nbsp;"&rs("S_Cs")&"</td>"
response.Write "<td align='center' width='15%'>"&rs("S_Zt")&"</td>"
response.write "<td align='center' width='15%'><a href='sbxx.asp?id="&rs("S_ID")&"' target='right'>查看</a></td>"

response.Write "</tr>"
  rs.movenext
  next 
%>

------解决方案--------------------
试试去。
VB code
<%
Dim cnstr, epage, i, id
id = request.QueryString("id")
cnstr = "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.MapPath("./sb.mdb")
Dim rs
Set cn = server.CreateObject("adodb.connection")
cn.Open cnstr
sql = "select * from shenbao where U_ID="&id&" and S_Zt='已审核' order by S_time desc "
Set rs = server.CreateObject("adodb.recordset")
rs.Open sql, cn, 1, 1
If (rs.bof And rs.EOF) Then
Else
    rs.pagesize = 20
    '设置每页记录数
    If request("page")<>"" Then
        epage = CInt(request("page"))
        '取当前的页数
        If epage<1 Then epage = 1
        '若当前页数小于1则置为1
        If epage>rs.pagecount Then epage = rs.pagecount
        '若当前页数大于最大页数值则置为最大页数
    Else
        epage = 1
        '否则页数为默认值1
    End If
    rs.absolutepage = epage
    '记录定位到当前页
    For i = 0 To rs.pagesize -1
        '循环显示本页记录
        If rs.EOF Then Exit For
        '若已经到记录末尾或没有数据则退出循环
        response.Write "<tr>"
        response.Write "<td align='left' width='40%' >&nbsp;&nbsp;"&rs("S_Cs")&"</td>"
        response.Write "<td align='center' width='15%'>"&rs("S_Zt")&"</td>"
        response.Write "<td align='center' width='15%'><a href='sbxx.asp?id="&rs("S_ID")&"' target='right'>查看</a></td>"

        response.Write "</tr>"
        rs.movenext
    Next
End If
rs.Close
Set rs = Nothing
%>

------解决方案--------------------
<%
dim cnstr,epage,i
cnstr = "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.MapPath("./sb.mdb") 
dim rs
set cn = server.CreateObject("adodb.connection")
cn.Open cnstr
sql = "select * from shenbao order by