从数据集 Vb.Net 生成数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18766270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generate an array from dataset Vb.Net
提问by Nilanjan
I am looking for a way to generate a string array from a dataset column. I have came across few examples as below in C# but couldn't write a VB.Net equivalent using LINQ. I do not want to use loop to achive the same.
我正在寻找一种从数据集列生成字符串数组的方法。我在 C# 中遇到过如下几个示例,但无法使用 LINQ 编写等效的 VB.Net。我不想使用循环来实现相同的目标。
string[] columnNames = (from dc in ds.Tables(0).Columns.Cast<DataColumn>()
select dc.ColumnName).ToArray();
Though my final objective is to pass these value to Interop Assembly Worksheet.Range().
虽然我的最终目标是将这些值传递给 Interop Assembly Worksheet.Range()。
回答by seph
Something like this should work in your case:
这样的事情应该适用于您的情况:
Dim arr As String() = (From myRow In ds.Tables(0).AsEnumerable
Select myRow.Field(Of String)("yourColumnName")).ToArray
回答by Gert Arnold
The VB equivalent is
VB 等价物是
Dim arr = (From dc In ds.Columns.Cast(Of DataColumn) Select dc.ColumnName) _
.ToArray()

