Populating Data table with dictionary keys and values

Hi everyone

I have a dictionary( of string, datatable).
I need to populate a datatable( keys, dictionary value).
I am able to get the value , not able to access the keys .


you can iterate over the dictionary and accessing key and value by following:

For each activity | kvp in yourDictVar | TypeArgument: KeyValuePair(Of String, DataTable)

  • access the key: kvp.Key
  • access the value (DataTable) kvp.Value

This is what I have ,
I do have the key .

In the outputdt →
input-> dict_InvoiceTable(key)
output ->strInvNo

in the excel , I need the entry as follows : where the invoice number is the key and the other fields from dictionary


kvp in yourDictVar - use kvp instead of key for the loop variable name


as mentioned aboe for the access

when the datatable is to enrich with the dictionary key information then update the column by using a for eacch row befor writing it to the excel

thia is what I am getting if I build a dt with columns string and datatable type ,then add datarow and then populate the excel

not getting .key and .value with loop var

share a screenshot from your type argument from for each activity, thanks

Also kindly note following:

was not mentioned, remove Keys and change typeargument as mentioned above to KeyValuePair(String, DataTable)

removed the keys
adddata row {kvp.key, kvp.value}

tried , excel looks the same as above

please reread the answers from above


For each | …

  • For each Row - row in kvp.Value
    • assign - update the row column with kvp.Key

this is what I did, the used this dt_temp towrite into the excel

Hi @Rajeena_M ,

This looks to be quite understandable, but for confirmation, Could you Provide us with Example data, as to What would be the Key and the Value of the Dictionary.

If it is the Invoice Number and Datatable, Could you show us a Visual on one of the Key Value Pairs.

Or According to this Image, Invoice Number is the key, Where Other Columns are from the Datatable and you would need the Output like the Above Image ?

I have used DU to extract the tables, its items table of a an invoice.
Table from Dataset
Column A(invoice number) is not from the table, extracted using ML extr
Then added to dictionary (string , datatable) → inside the foreach of DU
dict_InvoiceTable(invoice number, datatble)

I am using the Dictionary for further activities.
and write line to see the output.

Just wanted to see it in excel , as in the above pic.

@Rajeena_M ,

Please find the Example Workflow Below :

Combine_DT_in_Dictionary.zip (10.3 KB)

We can keep the Input data as required By Preparing the Input Data, then Work on the Output format that is Required.

  1. Preparing the Input Data
  • We have two tables in Excel, which we Read as Datatables
  • We then Add this to the Dictionary with a String as a Key.
  • This is to Replicate the Input Data format that you have.




  1. Creating the Output format as Required.
  • We create a Clone of the Datatable in the Dictionary and assign it to the Output Datatable, (i.e all tables are to be Expected in the same format)
  • We add the new Column Required.
  • We arrange the Column Names as Required
  1. Manipulate Data and Write Final Output
  • We iterate through the Dictionary
  • Create Temporary Datatables
  • Prepare/Manipulate the Datatable as Required
  • Merge the datatable to the Output

We use the Following Linq Query to Get the Data in the Form Required :

(From p In tempDT.AsEnumerable()
Group By x= New With { Key.a =p.Item("Invoice Number")}
Into Grp = Group Select tempDTClone.LoadDataRow ({grp(0)(0).ToString}.ToArray.Concat(Enumerable.Range(1,tempDT.Columns.Count-1).Select(Function(y)String.Join(Environment.NewLine,grp.select(Function(c) c(y).ToString))).ToArray).ToArray,False)).CopyToDataTable

We get the Output as below for the Input Data :

You would not need to Prepare the Input data as you already have the Dictionary(Of String, Datatable) available.

Let us know if you still face issues.

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