6-16.asp
来自「ASP+SQL Server动态网站开发从基础到实践教程」· ASP 代码 · 共 101 行
ASP
101 行
<html>
<head>
<title>GetRows方法应用</title>
</head>
<body>
<%
Dim ConnStr,myConn,mySQL,myRec,myPage,myPageSize
'首先获得用户的显示参数
'获得要显示的页数
myPage=request.querystring("whichpage") '获得需要显示的页数
If myPage="" then '如果为空,则显示第一页
myPage=1
end if
'获得每页的大小,即显示记录的条数
myPageSize=request.querystring("pagesize") '获得每页大小
'如果为空
If myPageSize="" then
myPageSize=5 '如果每页大小为空,则默认为5条记录
end if
ConnStr="Provider=SQLOLEDB;data source=(local);initial catalog=northwind;user id=sa;password=;" '参照表6-2的连接字符串
set myRec=Server.CreateObject ("ADODB.RecordSet")
myRec.ActiveConnection=ConnStr
'设定RecordSet的属性
'myRec.cursorlocation=aduseclient
myRec.cachesize=5
myRec.open "select * from customers",,1,3 '打开记录集
'设定分页设置
myRec.movefirst '移动到第一条记录
' 设定每页的大小,显示记录的条数
myRec.pagesize=mypagesize
'总页数
maxcount=cint(myRec.pagecount)
'设定要显示的是第几页
myRec.absolutepage=myPage
'用户记录每页显示的记录数
howmanyrecs=0
response.write "当前页:" & mypage & " 总页数:" & maxcount & "<br>"
response.write "<table border=1>"
'首先输出字段标题,用表格来表示
response.write "<tr><td>客户编号</td><td>公司名称</td><td>联系人</td></tr>"
do while not myRec.eof and cint(howmanyrec)<cint(mypagesize) '表示当前记录不是最后
'输出一条记录
response.write "<tr><td>" & myRec("customerid") & "</td><td>" & myRec("companyname") & "</td><td>" & myRec("contactname") & "</td></tr>"
'接着移动到下一条记录
myRec.movenext '注意一定要使用这个语句,否则会死循环
howmanyrec=howmanyrec+1
loop
response.write "</table>"
'接着显示其他的链接,用户导航到其他页
'首先获得当前网页的路径
scriptname=request.servervariables("script_name")
'循环显示所有的连接
for counter=1 to maxcount
If counter>=10 then
pad=""
end if
ref="<a href='" & scriptname & "?whichpage=" & counter
ref=ref & "&pagesize=" & mypagesize & "'>" & pad & counter & "</a>"
response.write ref & " "
if counter mod 10 = 0 then
response.write "<br>"
end if
next
myRec.close
set myRec=nothing
%>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?