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
public DataTable TopDataRow(DataTable dt, int count)
{
DataTable dtn = dt.Clone();
int i = 0;
foreach (DataRow row in dt.Rows)
{
if (i < count)
{
dtn.ImportRow(row);
i++;
}
if (i > count)
break;
}
return dtn;
}