使用LINQ从数据表中检索行

问题描述:

我有2个数据表,我需要创建一个新的数据表,其结果应显示为(datatable1-datatable2).
例如:datatable1具有ID(1,2,3,4),而datatable2具有ID(3,4).新的数据表应具有值(1,2)
我需要DataTable1中的所有行,除了DataTable2
如何使用LINQ做到这一点?请帮助

I have 2 datatable and I need to create new datatable which should show the result as(datatable1 - datatable2).
For eg: datatable1 has IDs(1,2,3,4) and datatable2 has IDs(3,4).The new datatable should have the values (1,2)
I need all the rows from DataTable1 except DataTable2
How can I do this using LINQ? pls help

您不需要LINQ.可以使用RowFilter或在DataTable上选择Select来实现.
You don''t need LINQ for this. It can be accomplished with RowFilter or Select on the DataTable


您可以像这样加入

You can join like this

var q = from a in Table1
                           join b in Table2 on a.ID equals b.id
                           select new
                           {
                               a.id,
                               a.Number,
                               a.Name 
                           };