How to convert list to datatable

I have three lists-Name, URL, Details. I want to convert these lists into a single datatable where each list is a column i.e. all the data in Name list will be in a single column ‘Name’ in datatable. Similarly for URL and Details. How would I do this?

According to me first of all u should use build datatable activity and then create the variable for each list item and use add row property to add each item in datatable.

I have 3 different list so how do I iterate?

Assuming that all the list have equal items, try this:
initiate a counter variable to 0
loop through one of the lists using for each activity. Within the loop :

For each listItem1 in list1
you can access items from each list like below


use datatable activities to append these as needed
increment counter with assign

counter = counter + 1


If you are processing your list in a For each list, then I would use the approach that was mentioned, which would involve you having an available Data Table like from Build Data Table, then use Add Data row as you process each item. You will probably use the items in the array property of the Add Data row like {text1, text2, text3} or text.Split(" "c) if it’s in a string.
(I don’t recommend using counters though)

If you are not processing each item in the list then you can simply convert it to a Data Table by using it in the form of a comma-delimitted string. Basically, you would want to prep it for a CSV file by joining the items together with commas and newline characters. You can join an array by doing String.Join(",",textarray) or String.Join(System.Environment.Newline,textarray), or if it’s already as a string, you can just replace the delimitter with a comma like text.Replace(" “,”,"). Once it is in the CSV format, just use Write Text file to a CSV extension, then you can read it back to a Data Table. There is also Generate Data Table, but it doesn’t work well.



As suggested by you I have iterated it like this:

But I am getting following error:

I have initiated datarow like this:

How do I resolve this?

Hi @shrutika,

How did you passed the values to add data row activity.?

I was able to resolve this by adding Capture in for each loop. Thank you for your help.

yup! that’s what i guessed too! :smiley:

Could you please try this. I think it would cover your query.
Main.xaml (9.9 KB)

1 Like

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