将源绑定到ArrayList [英] Binding source to ArrayList
本文介绍了将源绑定到ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我有一个BindingSource绑定到一个DataTable(来自sql数据库),有几列
I have a BindingSource bound to a DataTable(from sql database) with several columns
我需要得到来自绑定源的所有列名称并将它们添加到名称的arraylist中
I need to get all columns names from binding source and add them to an arraylist of names
如何做到这一点?
感谢您的帮助
推荐答案
这是一种方法。
Here is one way to do this.
Dim columnNames() As String = CType(bsCustomers.DataSource, DataTable).
Columns.Cast(Of DataColumn).
Select(Function(c) c.ColumnName).ToArray()
For Each col As String In columnNames
Console.WriteLine(col)
Next
编辑,对于类型化的数据集,可能有多个表格,这里我定位第一个表格。
Edit, for a typed data set were there may be more than one table, here I target the first table.
Dim cols = CType(bsCustomers.DataSource, DataSet).
Tables(0).
Columns.Cast(Of DataColumn).
Select(Function(c) c.ColumnName).ToArray
For Each col In cols
Console.WriteLine(col)
Next
这篇关于将源绑定到ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文