在adodb记录集中导入哈希表的字段

在adodb记录集中导入哈希表的字段

问题描述:

嗨有一个哈希表和adodb.recordset。 该字段的哈希表的名称是相同的字段adodb.recordset 我怎样才能在字段adodb.recordset字段值的哈希表没有手动做?在adodb记录集中导入哈希表的字段

Dim Tot As ADODB.Recordset 
Dim h As Hashtable = New Hashtable 

h("a") = 1 
h("b") = 2 
h("d") = 4 

记录TOT具有字段: “A”, “B”, “d”

我想记录导入的哈希值

感谢

+0

您想根据数据库中的记录更新散列表,其中列是键,数据是值? – 2010-10-26 10:13:05

+0

你在Hashtable中的关键和价值是什么? – 2010-10-26 10:29:43

+0

我已经举了一个例子 – 2010-10-26 10:31:52

因为我仍然不知道你的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(顺便说一句,你为什么需要这样的过时的东西?)。