asp中通过getrows实现数据库记录分页的一段代码

1@ Language = VBSCRIPT 
1 Option Explicit 
 1   
 2rem 在asp中通过getrows实现数据库记录分页的一段代码   
 3Dim iStart, iOffset   
 4iStart = Request("Start")   
 5iOffset = Request("Offset")   
 6  
 7if Not IsNumeric(iStart) or Len(iStart) = 0 then   
 8iStart = 0   
 9else   
10iStart = CInt(iStart)   
11end if   
12  
13if Not IsNumeric(iOffset) or Len(iOffset) = 0 then   
14iOffset = 30   
15else   
16iOffset = Cint(iOffset)   
17end if   
18  
19Response.Write "Viewing " & iOffset & " records starting at record " & iStart & "

<br/>

 1"   
 2  
 3Dim objConn, objRS   
 4Set objConn = Server.CreateObject("ADODB.Connection")   
 5'objConn.Open "DSN=MP3"   
 6dim connstr   
 7dim db   
 8db="csnjimageman.mdb"   
 9connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")   
10objconn.Open connstr   
11  
12Set objRS = Server.CreateObject("ADODB.Recordset")   
13objRS.Open "SELECT * FROM imageinfo", objConn   
14  
15Dim aResults   
16aResults = objRS.GetRows   
17  
18objRS.Close   
19Set objRS = Nothing   
20  
21objConn.Close   
22Set objConn = Nothing   
23  
24  
25Dim iRows, iCols, iRowLoop, iColLoop, iStop   
26iRows = UBound(aResults, 2)   
27iCols = UBound(aResults, 1)   
28  
29If iRows > (iOffset + iStart) Then   
30iStop = iOffset + iStart - 1   
31Else   
32iStop = iRows   
33End If   
34  
35For iRowLoop = iStart to iStop   
36For iColLoop = 0 to iCols   
37Response.Write aResults(iColLoop, iRowLoop) & " "   
38Next   
39Response.Write "

<br/>

1"   
2Next   
3  
4Response.Write "

<p>"
if iStart &gt; 0 then
'Show Prev link
Response.Write "<a ""="" &offset=" &amp; iOffset &amp; " getrows.asp?start=" &amp; iStart-iOffset &amp; _
" href="">Previous " &amp; iOffset &amp; "</a>"
end if

if iStop &lt; iRows then
'Show Next link
Response.Write " <a ""="" &offset=" &amp; iOffset &amp; " getrows.asp?start=" &amp; iStart+iOffset &amp; _
" href="">Next " &amp; iOffset &amp; "</a>"
end if

Published At
Categories with Web编程
Tagged with
comments powered by Disqus