0
我有以下功能返回二維數組
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")
會議( 「SearchFields」)是空的,而不是陣列。它返回前是2d數組,返回後不是2d數組。一直持續了近一個小時的努力。
我已經嘗試將GetSearchField2dArray的結果設置爲一個變量,它仍然有相同的問題。
你有沒有聽說過'ADODB.Recordset'對象的'GetRows()'方法? – Lankymart
@Lankymart:我也會建議'.GetRows',但看起來這個convert函數實際上是將列名和數據類型放入數組中,*不是*這些值。然後引發這個問題,爲什麼還要從查詢中返回多行? (還有,OP聽說過'sp_columns',或者更好,'SELECT name,system_type_id FROM sys.columns WHERE [object_id] = OBJECT_ID('dbo.tablename')'?) – Martha
@Martha所有的優點,但由於Kul-tigin,OP有他們半熟的答案,所以我懷疑他們會回來。嘆 – Lankymart