在C#中两个DataTable差异 [英] Difference of two DataTables in c#
本文介绍了在C#中两个DataTable差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个数据表如下:
dtOne
-------------------------
ID | Name
--------------------------
101 | ABC
102 | XYZ
103 | MNO
--------------------------
dtTwo
-------------------------
ID | Name
--------------------------
101 | ABC
102 | XYZ
--------------------------
我只是想要的结果作为为在dtOne数据
和不在dtTwo
(dtOne-dtTwo)
I just want the result as data which is in dtOne
and not in dtTwo
(dtOne-dtTwo)
dtResult
-------------------------
ID | Name
--------------------------
103 | MNO
--------------------------
我怎样才能做到这一点。
How can i achieve this .
推荐答案
要得到它的工作它能够更好地使用Linq为DataSet会很容易。
TO get it work its better to use Linq To DataSet will resolve it easily..
DataTable table1= ds.Tables["table1"];
DataTable table2= ds.Tables["table2"];
var diff= table1.AsEnumerable().Except(table2.AsEnumerable(),
DataRowComparer.Default);
这篇关于在C#中两个DataTable差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文