如何从 VB.NET 中的 DataSet 填充数组 [英] How to populate an array from a DataSet in VB.NET
本文介绍了如何从 VB.NET 中的 DataSet 填充数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 VB.NET 2010 从仅包含特定列的数据集中填充数组.是否有任何代码可以直接填充数组或者我必须使用查询?
I'm trying to populate an array from a dataset with only a specific column using VB.NET 2010. Is there any code to populate the array directly or must I make use of a query?
推荐答案
更新:
假设你想要一个字符串数组:
Assuming you want an array of String:
Dim arr As String() = (From myRow In ds.Tables(0).AsEnumerable
Select myRow.Field(Of String)("yourColumnName")).ToArray
或列表:
Dim list As List(Of String) = (From myRow In ds.Tables(0).AsEnumerable
Select myRow.Field(Of String)("yourColumnName")).ToList
<小时>
旧:
确保将 DisplayMember 设置为您要查看的列的名称:
Make sure the DisplayMember is set to the name of the column you want to see:
comboBox1.DataSource = ds.Tables(0)
comboBox1.DisplayMember= "NameOfColumn"
您可能还想将 ValueMember 属性设置为数据集中的 ID 字段名称.
You might also want to set the ValueMember property to the ID field name from your dataset.
这篇关于如何从 VB.NET 中的 DataSet 填充数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文