我發現要做到這一點是通過填充數組與字符串詞典的按鍵的最簡單方法所以
' Read data from database
Dim result As New ArrayList()
Dr = myCommand.ExecuteReader()
' Add each entry to array list
While Dr.Read()
' Insert each column into a dictionary
Dim dict As New Dictionary(Of String, Object)
For count As Integer = 0 To (Dr.FieldCount - 1)
dict.Add(Dr.GetName(count), Dr(count))
Next
' Add the dictionary to the ArrayList
result.Add(dict)
End While
Dr.Close()
,現在你可以遍歷結果用了這樣的循環:和對象的價值觀,像這樣
For Each dat As Dictionary(Of String, Object) In result
Console.Write(dat("ColName"))
Next
神似你會怎麼做,如果它是算了筆他的DataReader:
While Dr.Read()
Console.Write(Dr("ColName"))
End While
這個例子是使用MySQL/NET驅動器,但相同的方法可以與其他流行的數據庫連接器一起使用。
那麼,爲什麼你喜歡這種方法使用一個DataTable? – Doug 2013-04-26 16:23:03