How to get first N rows from a datatable
-
There is a method called datatable.select(string) to filter rows from a datatalbe But the string must contains one columnname in the datatable.I know nothing about the datatable,what i want to get is just the first N rows in the datatable. what should i do? Thanks
-
There is a method called datatable.select(string) to filter rows from a datatalbe But the string must contains one columnname in the datatable.I know nothing about the datatable,what i want to get is just the first N rows in the datatable. what should i do? Thanks
The DataTable's Rows property contains all the rows in the table. Just loop through it.
Nirandas, a developer from India. http://www.nirandas.com
-
There is a method called datatable.select(string) to filter rows from a datatalbe But the string must contains one columnname in the datatable.I know nothing about the datatable,what i want to get is just the first N rows in the datatable. what should i do? Thanks
-
IEnumerable<DataRow> dt = myDataTable.AsEnumerable().Take(3);
Now, you have a new DataRow list :)
modified on Wednesday, July 16, 2008 7:06 AM
-
thanks,thank you very much! accrooding your way i have solve my question.I could get the first 100Rows, But another question is how do i get the second 100 rows(101-200)? because i want to display 100rows/page. thanks for any help.
if you thing to make paging you can use this: Maybe it's a bit long way but I couldn't find another way. for first 100 records: IEnumerable<DataRow> dt = myDataTable.AsEnumerable().Take(100); for next n * 100 IEnumerable<DataRow> dt = myDataTable.AsEnumerable().Skip(n * 100); I meant if someone clicked 5. page n=5 IEnumerable<DataRow> dt1 = myDataTable.AsEnumerable().Skip(n * 100); than you need new table with your new rows (dt1) your secondTable = dt1 after that again IEnumerable<DataRow> dt2 = secondTable.AsEnumerable().Take(100); I hope it's helpfull
modified on Friday, July 25, 2008 8:31 AM
-
if you thing to make paging you can use this: Maybe it's a bit long way but I couldn't find another way. for first 100 records: IEnumerable<DataRow> dt = myDataTable.AsEnumerable().Take(100); for next n * 100 IEnumerable<DataRow> dt = myDataTable.AsEnumerable().Skip(n * 100); I meant if someone clicked 5. page n=5 IEnumerable<DataRow> dt1 = myDataTable.AsEnumerable().Skip(n * 100); than you need new table with your new rows (dt1) your secondTable = dt1 after that again IEnumerable<DataRow> dt2 = secondTable.AsEnumerable().Take(100); I hope it's helpfull
modified on Friday, July 25, 2008 8:31 AM