Getting an Error while converting Dict to DataTable

Hi Team,
Getting an Error while converting Dict to DataTable, PFA Image for Dict syntax and DT syntax as well… pls chekc what is the issue

Hi @Devasaiprasad_Kakumanu

The error is because you are using for each row in datatable & giving dictionary instead of datatable variable. You will have to use for each not for each row in datatable.

Follow these steps:

  1. Use the Build DataTable activity to create a DataTable with columns “Key” (of type Integer) and “Value” (of type String).

  2. Use a For Each activity to iterate through the dictionary.

  3. Inside the loop, use the Add Data Row activity to add rows to the DataTable for each key-value pair.

Try this for converting dict to datatable

https://youtu.be/ZhrHEgWXXrk?si=WBTo33hvWQXB1M8g

Ref:

Hope this helps :slightly_smiling_face:

1 Like

@Devasaiprasad_Kakumanu
By using linQ we can convert Dict to datatable

Newtonsoft.Json.Linq.JArray.FromObject({Dict}).ToObject(of System.Data.Datatable)

1 Like

@Devasaiprasad_Kakumanu
need to use For each activity as you are converting Dict to Datatable

Cheers!!

1 Like

THis is the Method i am about to try but missed adding .ToObject(of System.data.datatable)

Thank you

HI,

Can you try the following sample?

dt = dict.Select(Function(kv) dt.LoadDataRow({kv.Key,kv.Value},False)).CopyToDataTable()

Sample
Sample20231124-5.zip (3.0 KB)

Regards,