网站首页 > 知识剖析 正文
将通过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按日期统计就餐时段刷卡及人数(数组字典内置函数去重排序)
- 04-29php开发者composer使用看这一篇就够了
- 04-29引用和变量声明在不同语言中的实作
- 04-29PHP 没你想的那么差
- 04-29Ubuntu linux 上的 Nginx 和 Php 安装
- 04-29CentOS下通过yum搭建lnmp(单版本PHP)
- 04-29为什么 PHP8 是个高性能版本
- 04-29PHP8函数包含文件-PHP8知识详解
- 04-29使用无参数函数进行命令执行
- 最近发表
- 标签列表
-
- 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)