我用asp连接access数据库的一个表,并且带分页的如何写代码?
1个回答
展开全部
<%
set cnn=server.createObject("adodb.connection")
cnn.provider="Microsoft.jet.oledb.4.0"
cnn.connectionString="Data source=" & server.mappath("db.mdb")
cnn.open
dim sql
sql="select * from news order by indate desc"
set rs=server.createObject("adodb.recordset")
rs.open sql,cnn,1,1
rs.pageSize=4
dim pageNo
pageNo=cint(request.queryString("pageNo"))
if pageNo<1 or isnumeric(pageNo)=false then pageNO=1
if pageNo>rs.pageCount then pageNo=rs.pageCount
rs.absolutePage=pageNo
dim i
i=1
%>
<table border=1>
<tr>
<th>编号 <th>标题
<%
do while not rs.eof and i<=rs.pageSize
%>
<tr>
<td><% =rs(0)%> <td><a href=news/show.asp?id=<% =rs(0)%> target="_blank"><% =rs(1)%></a>
<%
i=i+1
rs.moveNext
loop
%>
</table>
<div>
<table border=0>
<tr>
<td>
共<% =rs.recordCount%>条
当前页次:<% =pageNo%>/<% =rs.pageCount%>
共<% =rs.pageCount%>页
<% if pageno<=1 or rs.recordCount<=rs.pageSize then %>
首页|
<% else%>
<a href=news/?pageNo=1>首页</a>|
<% end if%>
<% if pageno<=1 or rs.recordCount<=rs.pageSize then %>
上一页|
<% else%>
<a href=news/?pageNo=<% =pageNo-1%> >上一页</a>|
<% end if%>
<% if pageno>=rs.pageCount then %>
下一页|
<% else%>
<a href=news/?pageNo=<% =pageNo+1%> >下缓信一页</a>|
<% end if%>
<扰孝轮% if pageno>=rs.pageCount then %>
尾页|
<% else%>
<a href=news/?pageNo=<慎渗% =rs.pageCount%> >尾页</a>|
<% end if%>
<select name="jump" onchange="javascript:window.open('?pageNo='+ this.options[this.selectedIndex].value,'_self')">
<%
dim page
for page=1 to rs.pageCount
if page=cint(pageNo) then%>
<option value=<% =page%> selected ><% =page%> </option>
<%else%>
<option value=<% =page%> ><% =page%></option>
<%end if
next
%>
</select>
</td>
</tr>
</table>
</div>
<%
rs.close
set rs=nothing
cnn.close
set cnn=nothing
%>
这是我用的代码,你可以稍微改一下就能用了
set cnn=server.createObject("adodb.connection")
cnn.provider="Microsoft.jet.oledb.4.0"
cnn.connectionString="Data source=" & server.mappath("db.mdb")
cnn.open
dim sql
sql="select * from news order by indate desc"
set rs=server.createObject("adodb.recordset")
rs.open sql,cnn,1,1
rs.pageSize=4
dim pageNo
pageNo=cint(request.queryString("pageNo"))
if pageNo<1 or isnumeric(pageNo)=false then pageNO=1
if pageNo>rs.pageCount then pageNo=rs.pageCount
rs.absolutePage=pageNo
dim i
i=1
%>
<table border=1>
<tr>
<th>编号 <th>标题
<%
do while not rs.eof and i<=rs.pageSize
%>
<tr>
<td><% =rs(0)%> <td><a href=news/show.asp?id=<% =rs(0)%> target="_blank"><% =rs(1)%></a>
<%
i=i+1
rs.moveNext
loop
%>
</table>
<div>
<table border=0>
<tr>
<td>
共<% =rs.recordCount%>条
当前页次:<% =pageNo%>/<% =rs.pageCount%>
共<% =rs.pageCount%>页
<% if pageno<=1 or rs.recordCount<=rs.pageSize then %>
首页|
<% else%>
<a href=news/?pageNo=1>首页</a>|
<% end if%>
<% if pageno<=1 or rs.recordCount<=rs.pageSize then %>
上一页|
<% else%>
<a href=news/?pageNo=<% =pageNo-1%> >上一页</a>|
<% end if%>
<% if pageno>=rs.pageCount then %>
下一页|
<% else%>
<a href=news/?pageNo=<% =pageNo+1%> >下缓信一页</a>|
<% end if%>
<扰孝轮% if pageno>=rs.pageCount then %>
尾页|
<% else%>
<a href=news/?pageNo=<慎渗% =rs.pageCount%> >尾页</a>|
<% end if%>
<select name="jump" onchange="javascript:window.open('?pageNo='+ this.options[this.selectedIndex].value,'_self')">
<%
dim page
for page=1 to rs.pageCount
if page=cint(pageNo) then%>
<option value=<% =page%> selected ><% =page%> </option>
<%else%>
<option value=<% =page%> ><% =page%></option>
<%end if
next
%>
</select>
</td>
</tr>
</table>
</div>
<%
rs.close
set rs=nothing
cnn.close
set cnn=nothing
%>
这是我用的代码,你可以稍微改一下就能用了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询