Take first n number of rows and next n and so on from datatable

Hi all,

Please guide me on the below problem.

For example I have 450 rows in a datatable,this number of rows may changes everytime,
In this datatable,I need to take first 100 and and next 100 and so on . until all row complete in a datatable.

Guide me how can I do this.

Hi @yashashwini2322 ,

  1. Read Range (Read data from DataTable)dt

  2. Assign: chunkSize (int) = 100

  3. For Each loop (TypeArgument: DataRow)
    Assign: chunk(data table ) = dt.AsEnumerable().Skip(index * chunkSize).Take(chunkSize).CopyToDataTable()
    Process your data

     Assign: index = index + 1
    

Hope this helps .

Hi @yashashwini2322

Condition in If
dt.AsEnumerable.Chunk(100).Select(Function(a) a.CopyToDataTable).ToList

Check the below xaml file.
Main.xaml (11.7 KB)

Regards

Hello!

What you can do first is count the total rows of the DataTable (let’s call it “dt_input”). Just add an assign activity, create an int32 type variable (let’s call it “int_dtRowsCount”) and calculate the rows count → dt_input.RowCount.

Once you have the total number of rows you can divide the total amount by the size you want to split the DT (in this case “int_SplitSize” variable = 100). Then, you need to round up that number and that will be the number of iterations to loop through. For this example it will be

dbl_Iterations = Math.Ceiling(int_dtRowsCount/int_SplitSize)

Once you have this number, you can control the iterations in a for each loop using that as index

Hope it also helps :slight_smile:

Fran

It’s not working can you send me the xaml?

Can you send me the zip folder of this process.

Hi @yashashwini2322

please find the below zip file:
BlankProcess38.zip (133.5 KB)

Regards