程序代码
<%
'//分页函数
'//psize:每页显示的数据数
'//pindex:当前页码
'//tbName:表名
'//keyIndex:根据什么字段分页,一般是自增长类型(access数据库的自动编号)
'//where:查询条件
'//order:排序条件,缺省为" order by " &keyIndex &" desc"
'//总记录数与总页数可从返回的结果集中直接获取,字段datacount存储总记录数,字段pagecount存储总页数
private pindex,datacount,pages
'datacount = 0
'pages = 1
public function changePage(psize,tbName,keyIndex,where,order)
dim sqlstring
pindex = Trim(Request.QueryString("page"))
if not isnumeric(psize) or psize="" then psize=1'//每页显示的数据数
if not isnumeric(pindex) or pindex="" then pindex=1'//当前页码
if order="" then order=" order by " & keyIndex & " desc"
'//获取总数据数
'dim datacount,pages
set rs=conn.execute("select count(*) as datacount from " & tbName & " where 1=1 " & where)
datacount = rs("datacount")'//总记录数
rs.close
set rs=nothing
'//计算总页数
if (datacount mod psize)=0 then
pages=datacount \ psize
else
pages=datacount \ psize + 1
end if
'//
if cint(pindex)>pages then pindex=pages
'拼接sql字符串
if pindex<=1 then
sqlstring="select top " & psize & " *," & datacount & " as datacount," & pages & " as pagecount from " &_
tbName & " where 1=1 " & where & " " & order
else
sqlstring="select top " & psize & " *," & datacount & " as datacount," & pages & " as pagecount from " &_
tbName & " where 1=1 and " & keyIndex & " not in(select top " & (pindex-1)*psize & " " & keyIndex & " from " &_
tbName & " where 1=1 " & where & " " & order & ") " & where & " " & order
end if
'Response.Write(sqlstring)
set changePage=conn.execute(sqlstring)
end function
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |