Datatable to Multidimensional Array

我们两清 提交于 2019-11-26 22:06:26

问题


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...


回答1:


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();



回答2:


yourTable.AsEnumerable().Select(row => row.ItemArray).ToArray()




回答3:


try dt.Rows.Cast().Select(//datarow to strings)



来源:https://stackoverflow.com/questions/8932900/datatable-to-multidimensional-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!