Vb.net 导入哈希表';adodb记录集中的s字段
我有一个哈希表和一个adodb.recordset。 哈希表字段的名称与adodb.recordset字段的名称相同 如果不手动导入字段adodb.recordset中哈希表的字段值,如何导入 前 记录集tot有字段:“a”、“b”、“d” 我想在记录集中导入哈希表值Vb.net 导入哈希表';adodb记录集中的s字段,vb.net,hashtable,adodb,Vb.net,Hashtable,Adodb,我有一个哈希表和一个adodb.recordset。 哈希表字段的名称与adodb.recordset字段的名称相同 如果不手动导入字段adodb.recordset中哈希表的字段值,如何导入 前 记录集tot有字段:“a”、“b”、“d” 我想在记录集中导入哈希表值 谢谢因为我仍然不知道哈希表的键/值是什么,我假设db中只有一条记录,记录的字段名(列)是键,这些字段的值是哈希表中该键的值(字段名) 这应该行得通,不过恐怕你的要求是别的 Dim hash As New Dictionar
谢谢因为我仍然不知道哈希表的键/值是什么,我假设db中只有一条记录,记录的字段名(列)是键,这些字段的值是哈希表中该键的值(字段名) 这应该行得通,不过恐怕你的要求是别的
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(顺便说一句,为什么您需要这些过时的东西?)同样有效。您想根据数据库中的记录更新哈希表,其中列是键,数据是值?哈希表中的键和值是什么?
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