To Break a Data table

Hi All,

Could someone please help me to break a data table into two table based on row index.

Thanks,
Anjali

Hi, Can you pleaase elaborate or share some screenshot
Thank you.

Let’s suppose a have a data table with value,

AAAAA
BB
CCC
Anjali
1
2
3
I want to break it at Anjali so that i will have,
AAA
BB
CCC
In one data table variable and,
1
2
3
In other data table variable.

You can use the following approach to break a data table.

Assuming the data table contains 10 rows.

count = 10

  1. halfCount = count/2 = 5
  2. newdt1= myDataTable.AsEnumerable().Skip(0).Take(halfCount).CopyToDataTable

newdt2= myDataTable.AsEnumerable().Skip(halfCount).Take(halfCount).CopyToDataTable

newdt1 contains first 5 rows
newdt2 contains last 5 rows

Skip - Will skip the given number of rows
Take - Will take the next given number of rows

Regards,
Karthik Byggari

4 Likes

Thanks for your help.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.