C# - Merge two DataTables where rows are duplicate

▼魔方 西西 提交于 2019-12-29 08:58:14

问题


I can find lots of information about merging two DataTables and dropping duplicate rows, but I need the opposite.

I need to know if anyone has an easy way to merge two DataTables where the result of the merge is a DataTable with only rows that exist in both tables.


回答1:


Like this:

var intersection = table1.AsEnumerable()
                         .Intersect(table2.AsEnumerable(), DataRowComparer.Default);

DataRowComparer compares rows by their column values.



来源:https://stackoverflow.com/questions/6833454/c-sharp-merge-two-datatables-where-rows-are-duplicate

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