网站首页 > 知识剖析 正文
将通过ADO查询得到的RecordSet数据集,保存到数组:
Function RecordsetToArray(rs As Object) As Variant
Dim results() As Variant
Dim headers() As Variant
Dim data As Variant
Dim i As Long, j As Long
' 检查记录集是否为空
If rs Is Nothing Then
RecordsetToArray = Empty
Exit Function
End If
' 检查记录集是否有记录
If rs.BOF And rs.EOF Then
RecordsetToArray = Empty
Exit Function
End If
' 获取字段名称作为标题行
ReDim headers(0 To rs.Fields.Count - 1)
For i = 0 To rs.Fields.Count - 1
headers(i) = rs.Fields(i).Name
Next i
' 使用GetRows方法将数据保存到数组中
data = rs.GetRows()
' 将标题和数据合并到一个数组中
ReDim results(LBound(data, 2) To UBound(data, 2) + 1, LBound(headers) To UBound(headers))
For i = LBound(headers) To UBound(headers)
results(0, i) = headers(i)
Next i
For i = LBound(data, 2) To UBound(data, 2)
For j = LBound(data, 1) To UBound(data, 1)
results(i + 1, j) = data(j, i)
Next j
Next i
' 返回结果数组
RecordsetToArray = results
End Function
- 上一篇: VBA中的字典之三,字典如何排序篇二
- 下一篇: js中常见的几种排序算法
猜你喜欢
- 2025-01-20 Excel中的6个经典排序技巧都不掌握,还敢称Excel达人?
- 2025-01-20 查询函数Choose、Lookup、Hlookup、Vlookup应用技巧解读
- 2025-01-20 一起学《C程序设计》第六课——数组、字符串及实战练习
- 2025-01-20 一文解决CSP-J考纲所有排序算法
- 2025-01-20 Excel VBA 自定义函数/数组字段定位/数组字段排序
- 2025-01-20 java基础,arrays类,Java的八种排序,冒泡排序
- 2025-01-20 excel中什么是数组,数组的作用是什么,这篇文章就带你入门
- 2025-01-20 16.9 数组 - 数据排序技术
- 2025-01-20 怎么求第K大的数,topK 问题(快排的应用)java
- 2025-01-20 VBA按日期统计就餐时段刷卡及人数(数组字典内置函数去重排序)
- 05-14HTML5教程从《HTML+CSS基础课程》学习笔记中的技巧
- 05-14HTML 简介
- 05-14豆包给我输出的html在线象棋源码(有点简单)
- 05-14零基础学习HTML之html框架内嵌框架和head头信息设置
- 05-14nodejs搭建服务器显示静态html页面
- 05-14一个简单的个人网站模板
- 05-14DinkToPdf: .Net轻松搞定Html转PDF生成,几分钟上手!
- 05-148行代码实现一个websoket
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)