Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two variables how can I get it as datatable and return it with foreach.
I want to keep linq query in datatable

linq querys:

var table1=from p in tableA.... etc

var table2=from p in tableB... etc

var except=table1.Except(table2);


I want to var variable get var variables datatable and return with foreach.

What I have tried:

var table1=from p in tableA.... etc

var table2=from p in tableB... etc

var except=table1.Except(table2);


I want to foreach but var variable define.So Datatable not write.

foreach( DataTable dt in except)
{
  Student st=new Student();
  st.Add(dt);
}
Posted
Updated 21-Oct-19 12:22pm

1 solution

Your "vars" are deferred LINQ queries (unrealized collections). You iterate them like any other:

C#
foreach (var v in table1 ){

   // etc.
}


FYI, you can "refactor" the "var" with VS intellisense.
 
Share this answer
 
Comments
Member 14169626 22-Oct-19 1:23am    
I want to convert to var to datatable.How to convert.

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