c#中两个DataTable的区别 [英] Difference of two DataTables in c#

查看:21
本文介绍了c#中两个DataTable的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据表如下

dtOne
-------------------------
  ID  |   Name 
--------------------------
 101  |  ABC
 102  |  XYZ
 103  |  MNO
--------------------------

dtTwo
-------------------------
  ID  |   Name 
--------------------------
 101  |  ABC
 102  |  XYZ
--------------------------

我只想要结果为 in dtOnenot in 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 To 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆