DataTable to SharePoint List/Dictionary

Hello,

I have DataTable with multiple columns and list on sharepoint. How can i convert that datatable to dictionary so i could use “Add List Item” activity?

I tried:

TableProduct.AsEnumerable.ToDictionary(Function(x) x.Item(“Number”).ToString,Function(x) x.Item(“Account”).ToString,Function(x) x.Item(“Date”).ToString,Function(x) x.Item(“Amount”))

But i got error that there is too many arguments.

How can i convert datable and add it?

image

1 Like

We would do like this:

TableProduct.AsEnumerable.ToDictionary(Function(x) LAMBDA_ForTheDictKey,Function(x) LAMBDA_ForTheDictVALUE)

maybe you can share some sample data with us

Hey Peter,

Could you explain me how to do it?

Let say it is my sharepoint list:

image

and i have datatable with the same columns

image

And i found that activity below to add list items, but this is accepting only dictionary(String as Key, Object as Value) and im totally stuck here. I want add all rows from my datatable as list items :frowning:

image

Hey @Add_Bddd

Please try the below,

dt_Sharepoint.AsEnumerable.Select(Function(row) dt_Sharepoint.Columns.Cast(Of DataColumn)().ToDictionary(Function(col) col.ColumnName, Function(column) row(column).ToString))

There is one more way of JSON serialization which is my personal fav but since you requested through linq here it is.

The above will give you a collection of dictionary items which can be looped through using a ForEach and passed into the AddListItem activity one by one.

Hope this helps.

Thanks
#nK

1 Like

Thank you @Nithin :slight_smile:

1 Like

Cool @Add_Bddd :slight_smile: :+1:

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