Does anyone know how to select datatable by row range? say if I need to pull out records in datatable from row #20 - #50.
The DataTables rows() and row() (also optionally cells() and cell() ) methods provide the ability to select rows from the table. What rows are selected and how the selector actually operates is controlled by this row-selector data type.
A DataRow represent a row of data in data table. You add data to the data table using DataRow object. A DataRowCollection object represents a collection of data rows of a data table.
The row selector is a component that acts like a visual filter for datasets. It takes one dataset, chops it up into various ranges based on its configuration, and lets the user choose the splices. Then it creates a virtual dataset that only contains the rows that match the selected splices.
If you want to include rows 20 and 50, I think this will work:
var rows = (from r in table.AsEnumerable()
select r).Skip(19).Take(31);
update:
or more succinctly:
var rows = table.AsEnumerable().Skip(19).Take(31);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With