1.建立Recordset對象
Dim objMyRst
Set objMyRst=Server.CreateObject(ADODB.Recordset)
objMyRst.CursorLocation=adUseClientBatch '客戶端可批次處理
objMyRst.CursorType=adOpenStatic '遊標類型為靜態類型
注意:Recordset物件不能用Set objMyRst=Connection.Excute strSQL的語句建立,因為其建立的Recordset物件為adOpenFowardOnly不支援記錄集分頁
2.打開Recordset對象
Dim strSql
strSql=select * from ietable
objMyRst.Oepn strSql,ActiveConnection,,,adCmdText
3.設定Recordset的PageSize屬性
objMyRst.PageSize=20
預設的PageSize為10
4.設定Recordset的AbsolutePage屬性
Dim intCurrentPage
intCurrentPage=1
objMyRst.AbsolutePage=intCurrentPage
AbsolutePage為1到Recordset物件的PageCount值
5.顯示數據
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>)
說明:
1. adOpenStatic,adUseCilentBatch,adCmdText為adovbs.inc定義的常數,要使用的話要把adovbs.inc拷到目前目錄中並包含於在程式中
<! --#Include File=adovbs.inc-->
2. PrintFielName,PrintFieldValue函數的程式碼如下:
<%
Function PrintFieldName(objMyRst)
'參數objMyRst是Recordset對象
'定義孌數
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)
'參數objMyRst是Recordset對象
'定義孌數
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