Thursday, November 1, 2012

Retrieving top 10 records from Data Table using LINQ in ASP.NET

The below code will retrieve top 10 records from the data table.

DataTable1.AsEnumerable().Take(10);


Note: Add using System.Linq on the top.


If intellesense is not showing up, add reference to System.Core


We can copy these records to another data table as below


DataTable1.AsEnumerable().Take(10).CopyToDataTable();


Happy coding…

No comments:

Post a Comment