How to the select top n rows from a datatable/dataview in ASP.NET? Currently I am using the following code, passing the table and number of rows to get the records. Is there a better way?
public DataTable SelectTopDataRow(DataTable dt, int count) { DataTable dtn = dt.Clone(); for (int i = 0; i < count; i++) { dtn.ImportRow(dt.Rows[i]); } return dtn; }
In framework 3.5, dt.Rows.Cast<System.Data.DataRow>().Take(n)
dt.Rows.Cast<System.Data.DataRow>().Take(n)
Otherwise the way you mentioned
1.4m articles
1.4m replys
5 comments
57.0k users