[英]Import hashtable's fields in a adodb recordset
嗨,有一個哈希表和一個adodb.recordset。 哈希表的字段名稱與adodb.recordset字段相同。如何手動將哈希表的字段值導入adodb.recordset字段中?
前
Dim Tot As ADODB.Recordset
Dim h As Hashtable = New Hashtable
h("a") = 1
h("b") = 2
h("d") = 4
記錄集tot具有字段:“ a”,“ b”,“ d”
我想在記錄集中導入哈希表值
謝謝
因為我仍然不知道HashTable的鍵/值是什么,所以我假設db中只有一條記錄,並且該記錄的字段名(列)是鍵,而這些字段的值就是值在HashTable中用於該鍵(字段名)。
盡管我擔心您的要求還有其他問題,但這應該可以工作。
Dim hash As New Dictionary(Of String, Object)'this is your "HashTable"'
Dim con As New SqlClient.SqlConnection(My.Settings.SQLSERV2_RM2)
Try
Using con
Using command As New System.Data.SqlClient.SqlCommand("SELECT idClaimStatus, ClaimStatusName FROM dimClaimStatus ORDER BY ClaimStatusName", con)
command.Connection.Open()
Using reader As System.Data.SqlClient.SqlDataReader = command.ExecuteReader
While reader.Read
For i As Int32 = 0 To reader.FieldCount - 1
Dim field As String = reader.GetName(i)
If Not hash.ContainsKey(field) Then
hash.Add(field, reader(i))
Else
hash(field) = reader(i)
End If
Next
End While
End Using
End Using
End Using
Catch ex As Exception
Throw
Finally
'nothing to do here because using closes the connection automatically'
End Try
我提供了一個DataReader示例,但是(希望)對ADODB.Recordset起作用(順便說一句,為什么您需要這種陳舊的東西?)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.