17/05/2002, 10:48
|
| | Fecha de Ingreso: octubre-2000 Ubicación: Juarez, Chih.
Mensajes: 161
Antigüedad: 24 años, 2 meses Puntos: 0 | |
Paginando con ADO Usando ADO puedes paginar datos N registros a la vez. Los registros son extraidos
N veces a la vez, para que el tiempo de acceso sea disminuido asi que los datos serán
fáciles de mostrar.
<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<!--#include virtual="/ADOVBS.inc"-->
<%
Const NumPerPage = 10
'Retrieve what page we're currently on
Dim CurPage
If Request.QueryString("CurPage") = "" then
CurPage = 1 'We're on the first page
Else
CurPage = Request.QueryString("CurPage")
End If
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=MyDB"
'Explicitly Create a recordset object
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
'Set the cursor location property
rs.CursorLocation = adUseClient
'Set the cache size = to the # of records/page
rs.CacheSize = NumPerPage
'Open our recordset
Dim strSQL
strSQL = "SELECT Name,Salary FROM Employee ORDER BY Name"
rs.Open strSQL, Conn
rs.MoveFirst
rs.PageSize = NumPerPage
'Get the max number of pages
Dim TotalPages
TotalPages = rs.PageCount
'Set the absolute page
rs.AbsolutePage = CurPage
'Counting variable for our recordset
Dim count
%>
<HTML>
<BODY>
<B>Name - Salary</B><BR>
<%
'Set Count equal to zero
Count = 0
Do While Not rs.EOF And Count < rs.PageSize
Response.Write(rs("Name") & " - " & rs("Salary") & "<BR>")
Count = Count + 1
rs.MoveNext
Loop
'Print out the current page # / total pages
Response.Write("Page " & CurPage & " of " & TotalPages & "<P>")
'Display Next / Prev buttons
if CurPage > 1 then
'We are not at the beginning, show the prev button
Response.Write("<INPUT TYPE=BUTTON VALUE=PREV ONCLICK=""document.location.href='thisfi le.asp?curpage=" & curpage - 1 & "';"">")
End If
if CInt(CurPage) <> CInt(TotalPages) then
'We are not at the end, show a next button
Response.Write("<INPUT TYPE=BUTTON VALUE=NEXT ONCLICK=""document.location.href='thisfi le.asp?curpage=" & curpage + 1 & "';"">")
End If
%>
</BODY>
</HTML> |