,你可以使用字典,並有每個字段的名稱作爲關鍵字,那麼每列作爲數組的值: 考慮這一點。
首先,declate字典:
Set oData = Server.CreateObject("Scripting.Dictionary")
現在使用這兩個循環填充數據:
For Each fld In rs.Fields
oData.Add fld.Name, Array()
Next
Do Until rs.EOF
For Each fld In rs.Fields
tempArray = oData(fld.Name)
ReDim Preserve tempArray(UBound(tempArray) + 1)
tempArray(UBound(tempArray)) = rs(fld.Name)
oData(fld.Name) = tempArray
Next
rs.MoveNext
Loop
最後,你可以使用這樣的代碼顯示的所有列名:
Response.Write("Column names:<br />")
For Each fld In oData.Keys
Response.Write(fld & " ")
Next
Response.Write("<br />")
或顯示特定列的值:
Response.Write("Values for column named Id:<br />")
If oData.Exists("Id") Then
tempArray = oData("Id")
For x=0 To UBound(tempArray)
Response.Write(tempArray(x) & "<br />")
Next
Else
Response.Write("Such column does not exist")
End If
這是好的,但我需要把值返回到變量,這樣我可以在我的頁面上重用他們。 – Benzine