Hi, I have a data table as below. Now I want to to convert it to dictionary in such a way that column name should be the Key and the below value should the value of the dictionary. Can someone help me on this.
Read Range - Input: “YourFilePath”, Output: dtData
Assign - TypeArgument: Dictionary(Of String, String)
To: dictData
Value: New Dictionary(Of String, String)
For Each Row - Input: dtData
For Each Column - Input: dtData.Columns
Assign - To: dictData(Column.ColumnName)
Value: row(Column).ToString
End For Each Column
End For Each Row
// Now, dictData contains the desired dictionary with column names as keys and corresponding cell values as values.
dataDictionary= New Dictionary(Of String, String)
For Each row As DataRow In YourDataTable.Rows
For Each column As DataColumn In YourDataTable.Columns
Dim key As String = column.ColumnName
Dim value As String = row(column).ToString()
' Add the key-value pair to the dictionary
dataDictionary.Add(key, value)
Next
Next
' Now dataDictionary contains the data from the DataTable in dictionary format
Read Range workbook
For Each Row activity:
Input: yourDataTable
For Each activity (nested inside For Each Row):
Input: yourDataTable.Columns
TypeArgument: DataColumn
Assign activity (inside the nested For Each):
To: outputDictionary(row.Table.Columns(column.ColumnName).ToString())
Value: row(column).ToString()