Hello Team ,
i have a DT with 1 row and 5 columns (it may increase) , i want to convert this as dictionary,
i want the column header as the key to the dictionary and the row values as the value of the dictionary.

Like,
Hide price : false.
Quote price term : 0
Payment terms : YE55 etc …
rlgandu
(Rajyalakshmi Gandu)
2
@Akhil_Raveendran
Outdict=
YourDataTableVar.Columns.Cast(Of DataColumn)().ToDictionary(
Function(col) col.ColumnName,
Function(col) String.Join(vbCrLf, YourDataTableVar.AsEnumerable().Select(Function(row) col.ColumnName + ": " + row(col).ToString()).ToArray()))
Outdict=New Dictionary(Of String,String)
Parvathy
(PS Parvathy)
3
Hi @Akhil_Raveendran
→ Read Range Workbook:
Output-> dt
→ Use Below syntax in assign:
outputDict= dt.Columns.Cast(Of DataColumn)().ToDictionary(Function(col) col.ColumnName, Function(col) dt.Rows(0)(col))
outputDict is of DataType System.Collections.Generic.Dictionary(System.String,System.Object)
→ Use For Each loop
For Each kvp in outputDict
Log Message-> kvp.Key + ": " + kvp.Value.ToString
End For Each
Output:

Sequence.xaml (9.2 KB)
Hope it helps!!
2 Likes
Anil_G
(Anil Gorthi)
4
@Akhil_Raveendran
Please try this
Dictionaryvariable = dataTable.Columns.Cast(Of DataColumn).ToDictionary(function(x) x.ColumnName,function(x) dataTable.Rows(0)(x).ToString)
Cheers
1 Like
Parvathy
(PS Parvathy)
5
Hi @Akhil_Raveendran
→ Read Range Workbook Output-> dt
→ If you have multiple columns you can follow the below syntax in Assign:
Assign-> outputDict= dt.AsEnumerable().Select(Function(row) dt.Columns.Cast(Of DataColumn)().ToDictionary(Function(col) col.ColumnName, Function(col) row(col))).ToList()
outputDict is of DataType System.Collections.Generic.List(System.Collections.Generic.Dictionary(System.String,System.Object))
→ Use For Each loop
For Each dict in outputDict
For Each kvp in dict
Log Message-> kvp.Key + ": " + kvp.Value.ToString
End For Each
End For Each
Regards
1 Like
Hi @Akhil_Raveendran
- Read Excel File and stored DT as Variable (DataTable)

- Initialize Dictionary (of String,String)
- Use below Expression in Assign Activity
DT.Columns.Cast(Of DataColumn)().ToDictionary(Function(col) col.ColumnName, Function(col) DT.Rows(0)(col).ToString.Trim)
OUTPUT:

Hope it will helps you 
Cheers!!
2 Likes
system
(system)
Closed
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.