Split datatable into different files

I have a datatable with lets say 2300 rows, I also have a row limit of lets say 1000 rows per file. Now for this example I have to create 3 files, each file having at maximum of 1000 rows. The first file will have data from 1st to 1000th row, 2nd file should have data from 1001st to 2000th row and the 3rd file should have data from 2001st row to 2300rd row.

Hi,
Can you try as the following?

dt.AsEnumerable.Chunk(1000)

Regards,

2 Likes

Hi @SunnyJha

Try this

DT.AsEnumerable.Chunk(1000).Select(Function(a) a.CopyToDataTable).ToList

Cheers!!

1 Like

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