Subset a datatable based on the rows

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

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

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.

@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)

@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

If I’m using this I got error like “DataTable.AsEnumerable().Skip(2).CopyToDataTable” is not member of data table… what should I do…