组合几个DataTables DataRows(Combine several DataTables DataRows)

编程入门 行业动态 更新时间:2024-10-28 16:19:17
组合几个DataTables DataRows(Combine several DataTables DataRows)

我有一个具有相同结构的DataTables数据集。 我想在SINGLE linq查询中从这些表中获取单个DataRows集合

from sourceTab in ds.Tables.OfType&t;DataTable>() select sourceTab

然后我需要从每个表中选择数据行并将它们组合成一个列表

I have a Dataset of DataTables with same structure. I want to get a single collection of DataRows from these tables in SINGLE linq query

from sourceTab in ds.Tables.OfType<DataTable>() select sourceTab

Then I need to select datarows from each table and combine them into one list

最满意答案

使用SelectMany从每个表中选择所有行并将它们展平为一个序列:

from row in ds.Tables.Cast<DataTable>().SelectMany(t => t.AsEnumerable()) // filter, etc select row

如果您只想要所有行,那么请使用

ds.Tables.Cast<DataTable>().SelectMany(t => t.AsEnumerable())

Use SelectMany to select all rows from each table and flatten them into one sequence:

from row in ds.Tables.Cast<DataTable>().SelectMany(t => t.AsEnumerable()) // filter, etc select row

If you just want all rows, then use

ds.Tables.Cast<DataTable>().SelectMany(t => t.AsEnumerable())

更多推荐

本文发布于:2023-04-28 10:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1330925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:几个   组合   DataTables   DataRows   Combine

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!