ASP Recordset pagination method of displaying Data (Revised edition) _asp Foundation

Source: Internet
Author: User

1. Creating a Recordset object

Copy Code code as follows:

Dim Objmyrst
Set objmyrst=server.createobject ("ADODB. Recordset ")
Objmyrst.cursorlocation=aduseclientbatch ' client can be processed in batches
Objmyrst.cursortype=adopenstatic ' cursor type is static type

Note: The Recordset object cannot be established with a set Objmyrst=connection.excute strSQL statement because the Recordset object it creates is adopenfowardonly does not support recordsets paging
2. Open a Recordset object
Copy Code code as follows:

Dim strSQL
Strsql= "SELECT * from Ietable"
OBJMYRST.OEPN strsql,activeconnection,,, adCmdText

3. Set the PageSize property of a recordset
Copy Code code as follows:

Objmyrst.pagesize=20

The default pagesize is 10
4. Set the AbsolutePage property of a recordset
The following are the referenced contents:
Copy Code code as follows:

Dim Intcurrentpage
Intcurrentpage=1
Objmyrst.absolutepage=intcurrentpage

AbsolutePage is a PageCount value of 1 to the Recordset object
5. Display data
Copy Code code as follows:

Response.Write ("<table>")
Printfieldname (Objmyrst)
For I=1 to Objmyrst.pagesize
Printfieldvalue (Objmyrst)
Objmyrst.movenext
If objmyrst.eof Then Exit for
Next
Response.Write ("</table>")

Description
1. Adopenstatic,adusecilentbatch,adcmdtext for Adovbs.inc defined constants, to use the words to copy Adovbs.inc to the current directory and included in the program
Copy Code code as follows:

<! --#Include file= "Adovbs.inc"-->

2. The code for the Printfielname,printfieldvalue function is as follows:
Copy Code code as follows:

<%
Function Printfieldname (Objmyrst)
' Parameter Objmyrst is a Recordset object
' Define the number of paragraph
Dim OBJFLD
Response.Write "<tr bgcolor= ' #CCCCCC ' >"
For each objfld in Objmyrst.fields
Response.Write "<td>" & Objfld.name & "</td>"
Next
Response.Write ("</tr>")
End Function
Function Printfieldvalue (Objmyrst)
' Parameter Objmyrst is a Recordset object
' Define the number of paragraph
Dim OBJFLD
Response.Write ("<tr >")
For each objfld in Objmyrst.fields
' Response.Write ' <td> & Objmyrst.fields (intloop). Value & "</td>"
Response.Write "<td>" & Objfld.value & "</td>"
Next
Response.Write ("<tr>")
End Function
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.