Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to convert sql query to linq using datatable.

SQL
select DISTINCT targeturl from internal where TargetURL NOT in (select DISTINCT url from Internal)


using this query, but still not getting the correct result.
C#
var List1 = dt.AsEnumerable().Select(c => c.Field<string>("URL")).Distinct().ToList();
  var List2 = dt.AsEnumerable().Select(c => c.Field<string>("TargetURL")).Distinct().ToList();
  var Targetname = List2.Except(List1.ToList()).ToList();
Posted

Nice example in the first answer on this[^] page.
 
Share this answer
 
Comments
Maciej Los 12-Feb-15 8:29am    
+5!
If i understand you correctly...
Try this:
C#
DataTable dstdt = dt.AsEnumerable().Select(c => c.Field<string>("TargetURL"))
                                .Except(dt.AsEnumerable().Select(c=>c.Field<string>("Url")))
                                .Distinct().CopyToDataTable();
 
Share this answer
 
v2
DataTable dstdt = dt.AsEnumerable().Select(c => c.Field("TargetURL"))
.Except(dt.AsEnumerable().Select(c=>c.Field("Url")))
.Distinct().CopyToDataTable();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900