您的位置广东网盟 > 文章资讯 > 软件应用 > 编程开发 > ASP技术 > 文章内容

asp中通过getrows实现数据库记录分页

作者:佚名  来源:本站整理  发布时间:2008-10-16 13:37:30

<%@ Language = VBSCRIPT %>
<% Option Explicit %>
<%
rem 在asp中通过getrows实现数据库记录分页的一段代码
Dim iStart, iOffset
iStart = Request("Start")
iOffset = Request("Offset")

if Not IsNumeric(iStart) or Len(iStart) = 0 then
iStart = 0
else
iStart = CInt(iStart)
end If

if Not IsNumeric(iOffset) or Len(iOffset) = 0 then
iOffset = 30
else
iOffset = Cint(iOffset)
end If

Response.Write "Viewing " & iOffset & " records starting at record " & iStart & "<BR>"

Dim objConn, objRS
Set objConn = Server.CreateObjeCT("ADODB.Connection")
'objConn.Open "DSN=MP3"
dim connstr
dim db
db="test.mdb"
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
objconn.Open connstr
Set objRS = Server.CreateObject("ADODB.Recordset")

objRS.Open "SELECT * FROM test", objConn

Dim aResults
aResults = objRS.GetRows
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing

Dim iRows, iCols, iRowLoop, iColLoop, iStop
iRows = UBound(aResults, 2)
iCols = UBound(aResults, 1)

If iRows > (iOffset + iStart) Then
iStop = iOffset + iStart - 1
Else
iStop = iRows
End If

For iRowLoop = iStart to iStop
For iColLoop = 0 to iCols
   Response.Write aResults(iColLoop, iRowLoop) & " "
Next
Response.Write "<BR>"
Next

Response.Write "<P>"

if iStart > 0 then
'Show Prev link
Response.Write "<A HREF=""?Start=" & iStart-iOffset & _
"&Offset=" & iOffset & """>Previous " & iOffset & "</A>"
end If

if iStop < iRows then
'Show Next link
Response.Write " <A HREF=""?Start=" & iStart+iOffset & _
"&Offset=" & iOffset & """>Next " & iOffset & "</A>"
end if
%>

Tags:广东网盟  
  •         用户名: 验证码: 验证码,看不清楚请点击刷新验证码 (注“”为必填内容。)


    文章评论: [ 查看全部 ] 网友评论
    关于网盟 | 网站帮助 | 广告合作 | 下载声明 | 友情连接 | 联系方式

    Copyright © 2003-2008 Gdwg.Net. All Rights Reserved .
    中国广东网管联盟设计维护.网站备案:粤ICP备08020875号