DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Select Some Records From Datatable And Copy To Resultant Datatable Using LINQ

12.30.2011
| 3090 views |
  • submit to reddit
        // The above query will fetch all the matching records for Id =1  from the datatable "test".

The "If" condition check the results and copies it to the datatable.
var query = from p in dsTest.Tables["test"].AsEnumerable()              
where p.Field<string>("Id") == "1"   select p;

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

<a href="http://www.java-forums.org/java-software/"><strong>Java Software</strong></a>