加入收藏 | 设为首页 | 会员中心 | 我要投稿 常州站长网 (https://www.0519zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

ASP分页显示Recordset数据的方法

发布时间:2024-01-02 09:50:00 所属栏目:Asp教程 来源:DaWei
导读: 建立Recordset对象

以下为引用的内容:
Dim objMyRst

Set objMyRst=Server.CreateObject(“ADODB.Recordset”)

objMyRst.CursorLocation=adUseClientBatch ‘客户
建立Recordset对象

以下为引用的内容:
Dim objMyRst

Set objMyRst=Server.CreateObject(“ADODB.Recordset”)

objMyRst.CursorLocation=adUseClientBatch ‘客户端可批量处理

objMyRst.CursorType=adOpenStatic’光标类型为静态类型

注意:Recordset对象不能用Set objMyRst=Connection.Excute strSQL的语句建立,因为其建立的Recordset对象为adOpenFowardOnly不支持记录集分页

打开Recordset对象

以下为引用的内容:
Dim strSql

strSql=”select * from ietable”

objMyRst.Oepn strSql,ActiveConnection,,,adCmdText

设置Recordset的PageSize属性

objMyRst.PageSize=20

默认的PageSize为10

设置Recordset的AbsolutePage属性

以下为引用的内容:
Dim intCurrentPage

intCurrentPage=1

objMyRst.AbsolutePage=intCurrentPage

AbsolutePage为1到Recordset对象的PageCount值

显示数据

以下为引用的内容:
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

%>

(编辑:常州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章