.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
abhays
satyapriyanayak
SP
Ashutosh Jha
ASPEvil

Home >> Code Snippets >> LINQ >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

LINQ query to get records on where criteria and copy to data table

Posted By:Maverick       Posted Date: July 21, 2011    Points: 40    Category: LINQ    URL: http://www.dotnetspark.com  

LINQ query to get records on where criteria and copy to data table
 

Hello All,

If you want some records from data table and move them to a resultant datatable then use the following LINQ query.

 var query = from p in dsXML.Tables["TargetCompound"].AsEnumerable()              where p.Field<string>("CompoundId") == "1" && p.Field<string>("SampleId") == "1"  select p;

   if (query.Count<DataRow>() > 0)   {        dtIstdCompund = query.CopyToDataTable<DataRow>();   }

The above query will fetch all the matching records for compoundId =1 and sampleId = 1 from the datatable "TargetCompound".

The "If" condition check the results and copies it to the datatable.

Hope it helps.


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend