如何将数据表转换为列表? [英] How to covert a DataTable into a List?
问题描述
如何将DataTable转换为列表?
我可以通过遍历表并在迭代中填充列表来做到这一点.
但是还有其他预定义的方法可以实现此任务吗?
How to covert a DataTable into a List?
I Can do it by looping through the table and populating a list in iterations.
But Is there any other predefined methods are there to achieve this task?
推荐答案
您是否首先进行了搜索:
http://stackoverflow.com/questions/208532/如何将数据表转换为通用列表 [
Did you do a search first:
http://stackoverflow.com/questions/208532/how-do-you-convert-a-datatable-into-a-generic-list[^]
如果您使用的是.NET 3.5,则可以使用DataTableExtensions.AsEnumerable(扩展方法),然后如果确实需要List< datarow>而不只是IEnumerable< datarow>您可以调用Enumerable.ToList:
IEnumerable< datarow>序列= dt.AsEnumerable();
或
List< datarow> list = dt.AsEnumerable().ToList();
If you''re using .NET 3.5, you can use DataTableExtensions.AsEnumerable (an extension method) and then if you really need a List<datarow> instead of just IEnumerable<datarow> you can call Enumerable.ToList:
IEnumerable<datarow> sequence = dt.AsEnumerable();
or
List<datarow> list = dt.AsEnumerable().ToList();
来自 ^ ]:)
First result from Google [^]:)
从我们自己的CP档案中查找:
将列表转换为数据表 [使用通用将数据表转换为集合 [
From our own CP archive, look here:
Converting a List to a DataTable[^]
Convert Datatable to Collection using Generic[^]
这篇关于如何将数据表转换为列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!