Subset a datatable based on the rows

datatable

#1

Hello,

I have a data table (dt1) with 100 rows with headers. I want another data table (dt2) with rowindex >58 from dt1. I tried using SELECT function, but wouldn’t work. Can anyone help me out.

Thank you


#2

Create one more data table and write the data in it when the rowindex>58


#3

Hi

You can skip first 58 rows and select the remaining with the below expression.

DataTable.AsEnumerable().Skip(2).CopyToDataTable

This expression returns a new datatable with 2 rows removed.


#4

@shivnagsudhakar Check attached zip file excel file contains 10 rows,it skips first five rows and copies from sixth row and saves in another data table

SkipRows.zip (12.6 KB)


#5

@shivnagsudhakar

You can try like this

dt2 = (From row in dt1.Select
        Where Convert.ToInt32(dt1.Rows.IndexOf(row))>58
       Select row).ToArray.CopyToDataTable

Now dt2 will have the rows whose index is greater than 58

Regards,
Mahesh