Loop thorough list of datatable

Hi,

I have a list of datatable,

How to loop through the datatable so i can use write range for each of the datatable and also how to find rows count for each of the datatable?

As it is a list of datatables, you can simply use for each activity @mashy2 to loop through

and datatable.rows.count will give you the count of datatable

Hi @mashy2

  • Use for each to iterate from the List.
  • Select Type argument of For each as System.data.datatable
  • Then Use write range To write the datatable and provide Item as datatable to write range.
  • To get the count of rows for Every datatable use item.rows.count.
    Thanks & Regards
1 Like

Hi,

I have lot of datatable,
How to use add to collection to create list of datatable.
This way seem wrong:
image

1 Like

@mashy2

  • Do you have all these in Excel files?
1 Like

nope, i create the datatable

1 Like

I hope we already have a list of datatable
If so may I know why do we need a list to be created with add to collections
— and to write and find the Count hope these steps could help you
—let’s take that you list of name out_dtlist
—now use a for each loop and pass the above variable as input and change the type argument as Datatable
— inside the loop use a write range activity from workbook activities and mention the datatable as item (the variable from for each loop as it holds the datatable now)
—mention the sheetname and filename as well in the write range activity
—and next to this use a write line activity like to get the count.
item.Rows.Count.ToString

Hope this would help you
Cheers @mashy2

1 Like

@mashy2
You can Create Array of data-table and store all data-table in the array like this{datatable1, datatable}

1 Like

In that case create a variable in the variable panel like this
Out_dtlist is the name
Type is System.Collections.Generic.List(of System.Data.Datatable)

And in the default value mention as
New list(of system.Data.Datatable)

— now in the add to collections
In the property collections mention the list variable like out_dtlist and in the item mention the datatable variable name we want to add

Hope this would help you
Cheers @mashy2

1 Like

Thank you so much for everyone help!!!

1 Like

Cheers @mashy2

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