2015-01-14 84 views
0

好像是什么存储多维数据vb.net存储多维数据

当我从数据库中检索记录的最简单的方法我想知道最简单的方法,我用一个数组来存储,我会用一些信息后来这样的

rowCtr = 0 
For Each dr As DataRow In dt.Rows 
    md(rowCtr, 0) = dr("member_id").ToString 
    md(rowCtr, 1) = dr("full_name").ToString 
    md(rowCtr, 2) = dr("status").ToString 
    md(rowCtr, 3) = dr("archived").ToString 

    ... 

    rowCtr = rowCtr + 1 
Next 

访问特定成员的数据,我用这个

'first i loop through the md array to get the array index (ind) of a member 
'then, i can get the data of a member by using this 
md(ind, 0) 'To get the id 
md(ind, 1) 'To get the full name 

它有点困难,因为我总是需要知道并指定索引

我希望它是这样

md("443", "full_name") 'to get the full name 
md("443", "status") 'to get the status 

,其中443是其成员的ID,我用它作为第一个维度

我看了一下哈希表,字典,列表的关键 - 但我似乎无法找到在多维度的风格

如果可能的话使用它们一个很好的例子,我也想长度是动态的,而当我删除索引,其余的将填补它的现货 -

我还需要它有一个搜索方法,以查找member_id是否已经在列表中

最简单的方法是什么?请回复..谢谢

回答

2

不要打扰将数据复制到阵列 - 只使用DataTable直接:

Dim drMatch() As DataRow = dt.Select("member_id='443'") 
If drMatch.GetUpperBound(0) >= 0 Then 
    MsgBox(drMatch(0).Item("full_name").ToString) 
End If 

如果是组装不同来源的数据进入你的阵列,我会定义一个新的内存DataTable使用,而不是你的阵列。

+0

谢谢,伙计我会尝试 – jks

1

,如果你必须把它保存为一个数组(不知道为什么你会)你可以使用ENUM:

Enum Table1 
    Member_ID = 1 
    Full_Name = 2 
    Status = 3 
    archived = 4 
End Enum 

那么你的数组中,你可以这样做:

md("443", Table1.Full_Name) 'to get the full name 
    md("443", Table1.Status) 'to get the status 
+0

o,谢谢你告诉我关于Enum,我可能会在未来使用它.. – jks