How to get difference between two DataTables

前端 未结 8 902
自闭症患者
自闭症患者 2020-12-14 17:28

I have these two datatables and I want to get the difference between them. Here is an example:

Table1
-------------------------
ID  |   Name 
---------------         


        
8条回答
  •  余生分开走
    2020-12-14 18:12

    I will try to do it on a column level rather than a DataTable.

    IEnumerable id_table1 = table1.AsEnumerable().Select(val=> (int)val["ID"]);
    IEnumerable id_table2  = table2.AsEnumerable().Select(val=> (int)val["ID"]);
    IEnumerable id_notinTable1= id_table2.Except(id_table1);
    

    Just adding a .Select() to your answer...

提交回复
热议问题