Lets say I have a datatable having 100 rowitems. I have to make 5 datatables of 20 rowitems out of the given input datatable. How do i do this?

If there are 95 rowitems. I have to have individual datatable having rowitems are follow:
First Datatable having 20 rowitems
Second Datatable having 20 rowitems
Third Datatable having 20 rowitems
Fourth Datatable having 20 rowitems
Fifth Datatable having 15 rowitems

@companir

Please check this

cheers

Hi,

The following sample will help you.

Enumerable.Range(0,(dt.Rows.Count \ chunkSize)+1).Select(Function(i) dt.AsEnumerable.Skip(i*chunkSize).Take(ChunkSize).CopyToDataTable).ToArray

Regards,


The same workflow works only when chunksize is 999, but when i give 20 its showing an error. Help

Hi,

Can you share your current project as zip file?

Regards,

@companir

The error says that the input datatable has no data…please check the same

Cheers

Hi @companir ,

Test_Skip_Take.xaml (7 KB)

Try this. It works as per your requirement.

Hope it helps.

1 Like

Its working
Thanks @Yoichi
arigato gozaimasu

1 Like

@Yoichi I have a small change in workflow. How do I even get the column labels in the child excel from the parent excel?

Hi,

Can you elaborate? Each chunked datatable has column names of original datatable doesn’t it?

Regards,

Hi,

Sorry but i had a little mistake. The following expression is better because it also work in case of the number of rows is divisible by chunk size.

 Enumerable.Range(0,(dt.Rows.Count \ chunkSize)-CInt(dt.Rows.Count mod chunkSize >0)).Select(Function(i) dt.AsEnumerable.Skip(i*chunkSize).Take(ChunkSize).CopyToDataTable).ToArray

Regards,

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