You can compare two datatables by matching the columns and perform minus operations as you do in RDBMS.
public DataTable getLinq(DataTable dt1, DataTable dt2)
{
DataTable dtMerged =
(from a in dt1.AsEnumerable()
join b in dt2.AsEnumerable()
on
a["Query"].ToString() equals b["Query"].ToString()
into g
where g.Count() > 0
select a).CopyToDataTable();
return dtMerged;
}
Working example:
Consider datatable dt1 is having the data
Place | id | time |
---|
Russia | 1 | 22:10 |
Italy | 2 | 23:10 |
Australia | 2 | 00:10 |
India | 1 | 01:10 |
Pakistan | 6 | 02:10 |
Sri lanka | 1 | 03:10 |
China | 4 | 04:10 |
London | 1 | 05:10 |
Germany | 6 | 06:10 |
Iraq | 1 | 07:10 |
America | 4 | 08:10 |
India | 1 | 09:10 |
Consider datatable dt2 is having the data
Now we are going to perform MINUS operation. We are going to retrieve the rows from dt1 which has the places in dt2.
public DataTable getLinq(DataTable dt1, DataTable dt2)
{
DataTable dtMerged = (from a in dt1.AsEnumerable()
join b in dt2.AsEnumerable()
on a["Place"].ToString() equals b["Place"].ToString()
into g
where g.Count() > 0
select a).CopyToDataTable();
return dtMerged;
}
Result set :
Place | id | time |
---|
Italy | 2 | 30-12-1899 23:10 |
India | 1 | 01-01-1900 01:10 |
Iraq | 1 | 01-01-1900 07:10 |
India | 1 | 01-01-1900 09:10 |