Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data table select top 5 rows

Tags:

c#

datatable

Hi is there any way to select top 5 rows from a data table without iteration?

like image 876
sumana shabeeb Avatar asked Jul 14 '10 05:07

sumana shabeeb


People also ask

How to SELECT top 5 rows from datatable in c#?

either you can use linq or for loop the datatable for 5 time and fetch the records in a new datatable. var query = myDataTable. AsEnumerable(). Take(5);

How do you select rows in a data table?

You can click the first cell in the table row, and then press CTRL+SHIFT+RIGHT ARROW. Click the upper-left corner of the table. The following selection arrow appears to indicate that clicking selects the table data in the entire table.


1 Answers

I think, You can use LINQ:

datatable.AsEnumerable().Take(5);
like image 149
Pavel Belousov Avatar answered Sep 28 '22 20:09

Pavel Belousov