asp程序中连接数据库并输出带分页的数据代码示例
以下是ASP连接数据库并输出带分页的数据的代码示例:
<% ' 设置分页参数 pageSize = 10 ' 每页显示的记录数 currentPage = Request.QueryString("page") ' 当前页数 if currentPage = "" then currentPage = 1 ' 如果没有指定当前页数,则默认为第一页
' 连接数据库 set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("data.mdb")
' 查询记录总数 set rsCount = conn.Execute("SELECT COUNT(*) AS total FROM users") total = rsCount("total") rsCount.Close
' 计算总页数 totalPages = Int((total - 1) / pageSize) + 1
' 查询当前页的记录 set rs = conn.Execute("SELECT * FROM users ORDER BY id DESC LIMIT " & (currentPage - 1) * pageSize & "," & pageSize)
' 输出记录 response.write "
| " & rs("id") & " | " response.write "" & rs("name") & " | " response.write "" & rs("age") & " | " response.write "
' 输出分页链接 if totalPages > 1 then response.write "
rs.Close conn.Close set rsCount = nothing set rs = nothing set conn = nothing %
原文地址: http://www.cveoy.top/t/topic/faid 著作权归作者所有。请勿转载和采集!