Multiple key value pairs todictionary

Hello i have been trying to convert a datatable into dictionary using this code:

(From d In dt.AsEnumerable
Let kvp = New KeyValuePair(Of string, string)(d(1).toString,d(2).toString)
Select kvp).ToDictionary(of string, string)Function (x) x.Key, Function (x) x.Value)

My question is what if i need to define multiple kvps based on a specific column of the dt, example

mydt would be like this


my dictionary should look like this


Appreciate your help guys.



find some starter help here:
DtToDict_MultiKVP.xaml (10.1 KB)


Hello @ZARA_Clark_Vincent_M
on what condition you will be deciding the when to choose col A and when to choose col B…?

Thanks Peter it worked

in the example i provided it is based on category column. Thanks

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