vbscript 将Recordset列复制到数组

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 将Recordset列复制到数组相关的知识,希望对你有一定的参考价值。

Function CopyRecordsetColumnToArray(ByVal adoRecSet As ADODB.Recordset, ByVal columnName As String) As Variant
'Description:   Saves one column af a Recordset to an Array
'Input:         Recordset object; column name (string)
'Output:        1 column wide 2D Array

'******   DEKLARÁCIÓK   ********************
Dim tempArr()     As Variant
Dim i             As Long
'*******************************************

    With adoRecSet
        ReDim tempArr(0 To .RecordCount - 1, 0 To 0)
    
        .MoveFirst
        i = 0
        Do While Not .EOF
        '   Save record value
            'if value is NULL then relace it to vbNullString 
            If IsNull(.Fields(columnName).Value) Or .Fields(columnName).Value = "NULL" Then
                tempArr(i, 0) = vbNullString
            Else
                tempArr(i, 0) = adoRecSet.Fields(columnName).Value
            End If
            adoRecSet.MoveNext
            i = i + 1
        Loop
    End With
    
'   RETURN
    CopyRecordsetColumnToArray = tempArr

End Function

以上是关于vbscript 将Recordset列复制到数组的主要内容,如果未能解决你的问题,请参考以下文章

vbscript 将ADO Recordset复制到2D阵列

vbscript 将RecordSet列写入范围

vbscript SQL到Recordset

vbscript ADO RecordSet类

vbscript 获取Recordset标题

vbscript 获取ADO Recordset标头