I want to get top 10 rows from a DataTable in the same order as the previous DataTable.
With the code I have below, I can have it sorted in dt1 and import only 10 rows into dt2 but it’s not importing the rows in the sorted order. I need it to keep the sorted order. Your help will be much appreciated.
DataTable dt2 = dt1.Clone();
dt1.DefaultView.Sort = "x DESC";
for (int i = 0; i < 10; i++)
{
dt2 .ImportRow(dt1.Rows[i]);
}
Just use a query and sorting like this:
Hope it helps!