I have a DataTable I am populating from SQL table with the following example columns
- ID
- Type
- Value
I am populating the DataTable with rows which are of a certain type. I want to select the rows 10 – 20 from my resulting DataTable:
Connect conn = new Connect();
SqlDataAdapter da = new SqlDataAdapter(SQL, conn.Connection());
//Creates data
DataTable d = new DataTable();
da.Fill(d);
DataRow[] result = d.Select();
In the above code I have omitted the main SQL, and currently I have no select for my DataRow array. I cannot find a way to reference the row numbers.
So for instance I am looking for something like Select("rownum > X && rownum < Y")
I have searched here, and a number of other resources to no avail. Any clues would be really handy, or just a simple not possible.
It’s always better to select only what you need from the database(f.e. by using the
TOPclause or a window function likeROW_NUMBER) instead of filtering it in memory.However, you can use
Linq-To-DataSetandEnumerable.Skip+Enumerable.Take:If you want a new
DataTablefrom the filtered result useCopyToDataTable, if you want aDataRow[]userows.ToArray().