我有以下功能
Function GetSearchField2dArray(tableName)
sql = "SELECT * FROM "&tableName&" WHERE TEST IS NULL"
set rstField = DataConn.execute(sql)
Dim rv : rv = ConvertSqlResponseTo2dArray (rstField, "")
set rstField = Nothing
GetTCLSSearchFields2dArray = rv
End Function
此函数采用sql结果集并使用ConvertSqlResponseTo2dArray
将其转换为2d数组。我已经确认rv
确实是一个完美的阵列。
这是ConvertSqlResponseTo2dArray供参考:
Function ConvertSqlResponseTo2dArray(rstField, strExclude)
iField_tmp = 0
ReDim arrField(2, 0)
For i = 0 To rstField.Fields.Count - 1
If InStr(strExclude, "," & rstField.Fields(i).Name & ",") = 0 Then
strFieldType = rstField.Fields(i).Type
ReDim Preserve arrField(2, iField_tmp)
arrField(0, iField_tmp) = rstField.Fields(i).Name
If strFieldType = adDate Or strFieldType = adDBDate Or strFieldType = adDBTime Or strFieldType = adDBTimeStamp Then
' Date
arrField(1, iField_tmp) = "date"
ElseIf strFieldType = adSmallInt Or strFieldType = adInteger Or strFieldType = adTinyInt Or strFieldType = adUnsignedTinyInt Or strFieldType = adUnsignedSmallInt Or strFieldType = adUnsignedInt Or strFieldType = adBigInt Or strFieldType = adUnsignedBigInt Then
' Integer
arrField(1, iField_tmp) = "num"
ElseIf strFieldType = adSingle Or strFieldType = adDouble Or strFieldType = adCurrency Or strFieldType = adDecimal Or strFieldType = adVarNumeric Then
' Decimal
arrField(1, iField_tmp) = "num"
ElseIf strFieldTYpe = adBoolean Then
' Boolean
arrField(1, iField_tmp) = "boolean"
Else
arrField(1, iField_tmp) = "string"
End If
iField_tmp = iField_tmp + 1
End If
Next
ConvertSqlResponseTo2dArray = arrField
End Function
然后我有我正在使用它的代码
Session("SearchFields") = GetSearchField2dArray("Test1")
Session(“SearchFields”)为空,而不是数组。它返回之前它是一个2d数组,而不是返回后的二维数组。一直在努力奋斗近一个小时。
我已尝试将GetSearchField2dArray的结果设置为变量,但仍然存在相同的问题。
答案 0 :(得分:2)
错字。 GetSearchField2dArray
返回Empty
,因为没有为其分配值。
函数的最后一行必须是GetSearchField2dArray = rv
而不是GetTCLSSearchFields2dArray = rv
。
请记住使用Option Explicit来防止此类混淆。