Reputation: 23
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.
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().
Upvotes: 0
Views: 7213
Reputation: 109255
The VB equivalent is
Dim arr = (From dc In ds.Columns.Cast(Of DataColumn) Select dc.ColumnName) _
.ToArray()
Upvotes: 1
Reputation: 694
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
Upvotes: 1