Looping through Data table List

Hi,

I’m having difficulty looping through this nested List. I can see that there are items in the collection, i just can’t access it as it comes up as System.Collections.Generic.List (rather than the list of items shown within the Watch window).

How would i achieve this in a write line activity?

Thanks

@qwerty1

After item(“Subject”)(0) to access the first item of the list and so on

Cheers

Hi @qwerty1 ,

Can you share the screenshot of add data row activity , where you are adding data to datatable?

I’ve just tried this & received the error ‘Option Strict On Disallows late binding’

I’m adding to collection as its of type List.

The Main datatable with type list column:
main dt

Saving list to main dt column Students
saveToDt

We will convert the Datacolumn value to the needed target datatype

Assign Activity:
mySubjectList = DirectCast(dt_MainStudent.Rows(0)("Subjects"), List(Of String))

For tracings we can do:
String.Join(“|”, mySubjectList)

Hi @qwerty1 ,

Instead of keeping the column type as list in Build Datatable, keep the column type as String for both “Subjects” and “Buildings” column.

In Assign Activity do as below:
dt_MainStudent.Rows(0).item(“Subjects”) = String.Join(", ",lst_Subjects)

If you still have any issue let us know?

Thanks but i have already collected all items in li_Subjects & then copied them in to dt_MainStudent.
I need to loop through each distinct student & obtain a note of all the subjects associated with them. Each class has multiple students, so fr each class i’m collecting the distinct student ID then all their subjects.

If i just put them back in to another list then all the subjects will be listed - not just for the distinct student

dt_MainStudent.Rows(0)("Subjects") will return an output of Datatype: Object (for direct access we also would see a late binding message)

So we convert it with e.g. the help of DirectCast

Thank you very much! That worked perfectly

When i’m looping through its only showing the first row of DirectCast(dt_MainStudent.Rows(0)(“Subjects”), List(Of String)) but when i change Rows(0) to (1) it shows the second line. Is there something else i can use to autoincrement within the loop please?

increase the row index when looping

  • manually
  • using For each XXX index out.

For further questions just open a new topic for this new question and provide us with more details of your modeling especially the different loops used so far

1 Like

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