1. Create Recordset object
Dim objMyRst
Set objMyRst=Server.CreateObject(ADODB.Recordset)
objMyRst.CursorLocation=adUseClientBatch 'The client can process in batches
objMyRst.CursorType=adOpenStatic 'The cursor type is static type
Note: The Recordset object cannot be created using the Set objMyRst=Connection.Excute strSQL statement, because the Recordset object it creates is adOpenFowardOnly and does not support record set paging.
2. Open Recordset object
Dim strSql
strSql=select * from ietable
objMyRst.Oepn strSql,ActiveConnection,,,adCmdText
3. Set the PageSize property of Recordset
objMyRst.PageSize=20
The default PageSize is 10
4. Set the AbsolutePage property of Recordset
Dim intCurrentPage
intCurrentPage=1
objMyRst.AbsolutePage=intCurrentPage
AbsolutePage is 1 to the PageCount value of the Recordset object
5. display data
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>)
illustrate:
1. adOpenStatic, adUseCilentBatch, adCmdText are constants defined by adovbs.inc. To use them, copy adovbs.inc to the current directory and include them in the program.
<! --#Include File=adovbs.inc-->
2. The code of PrintFielName,PrintFieldValue function is as follows:
<%
Function PrintFieldName(objMyRst)
'The parameter objMyRst is a Recordset object
'Define number
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)
'The parameter objMyRst is a Recordset object
'Define number
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