Is there an easy way to convert a Datatable to a multidimensional string array?
Maybe using LINQ
?
There's gotta be a better way than manually looping through all the columns/rows...
Is there an easy way to convert a Datatable to a multidimensional string array?
Maybe using LINQ
?
There's gotta be a better way than manually looping through all the columns/rows...
Linq is the answer. You can convert a DataTable
to IEnumerable using the AsEnumerable
method. Then, the ToArray()
converts it to an array.
var tableEnumerable = DataTableName.AsEnumerable();
tableArray = tableEnumerable.ToArray();
Cannot implicitly convert type 'System.Data.DataRow[]' to 'string[*,*]'
Any help would be greatly appreciated. –
Nic var foo = dt.AsEnumerable().Select(x => x.ItemArray).ToArray();
–
Nic yourTable.AsEnumerable().Select(row => row.ItemArray).ToArray()
© 2022 - 2024 — McMap. All rights reserved.