C# - Merge two DataTables where rows are duplicate

2019-01-28 07:40发布

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条回答
Emotional °昔
2楼-- · 2019-01-28 08:27

Like this:

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

DataRowComparer compares rows by their column values.

查看更多
登录 后发表回答