大家可能经常会遇到这种情况:
- sql="select * from table"
- set rs=conn.execute(sql)
- sql="select * from table"
- set rs=conn.execute (sql)
- arrA=rs.getrows '将记录集放在一个二维数组中
- response.write ubound(arrA,2)+1
- response.write ubound(arrA,1)+1
==========================================================
另外,还有一种获取记录总数的方法:
- jls= conn.execute("Select count(*) From table").getstring
GetRows 方法传回一个二维的阵列变数,每一行对应Recordset中的一笔记录,且每一列对应到记录中的栏位。此方法的语法如下:
- varArray = rs.GetRows([Rows], [Start], [Fields])
Fields 是可选择的栏位名称阵列,其用来限制要读取的资料量。(也可指定单一栏位名称、单一栏位索引、或者一个栏位索引阵列)。当设定 Rows 为少於Recordset记录笔数时,第一笔未读取的记录变成现行记录。若省略 Rows 参数或设定为-1-adGetRowsRest或大於未读取的笔数时,GetRows 方法会读取所有记录并让Recordset在EOF状态,而不会产生任何错误。
当处理目的变数阵列的资料时,应该记得资料储存方式是有点相反的感觉:阵列中第一维定义Recordset的栏位(资料行),第二维定义Recordset的资料列。以下有个载入Recordset内所有记录某三个栏位的范例:
- Dim values As Variant, fldIndex As Integer, recIndex As Integer
- values = rs.GetRows(, , Array("LastName", "FirstName", "BirthDate"))
- For recIndex = 0 To UBound(values, 2)
- For fldIndex = 0 To UBound(values)
- Print values(fldIndex, recIndex),
- Next
- Next
推荐阅读
- 学习心得|生成随机密码
- .NET+C#|AspNETPager的用法
- .NET+C#|ASP.NET 2.0中Theme、MasterPage和代码国际化
- asp.net|在ASP中读取数字证书(ASP.NET)
- 服务器相关|SQL Injection
- WEB技术|Paypal API说明
- asp|ASP函数大全
- asp|以前用ASP写的留言本