How to convert datatable into dictionary array?

Hi,

I am using Office 365 package and using get list items to fetch ceratin list items. Output of this activity is datatable but I need to have this datatable as a dictionary array.

Datatable → Array of [dictionary(String,Object)]
getListItems → dict as shown in variable panel below:

image

Regards
Sonali

Hi @sonaliaggarwal47,
Use below code
dictArray= dt.AsEnumerable() _ .Select(Function(row) New Dictionary(Of String, Object) From { {row("Column1").ToString(), row("Column2")}}).ToArray()

Regards,
Arivu

@sonaliaggarwal47 ,
follow the below steps
Create a dictionary and initialize it
dictionary = New Dictionary(Of String, Object())

Use assign activity
dictionary = dt.AsEnumerable().ToDictionary(
Function(row) row(“YourKeyColumnName”).ToString(),
Function(row) row.ItemArray)

cheers!!

Hi @Somanath1 @arivu96,

This code is applicable when there is 1 row in datatable and we create dictionary.

My case, datatable have multiple rows, so my dictionary is an array like below

Dictionary(Of String, Object)

I am not able to initialize the dictionary array as number of rows are unknown.

Regards
Sonali

Hi @sonaliaggarwal47,

Can you provide the sample input and expected output.

Regards,
Arivu

1 Like