Convert Datatable to Dictionary

Hello, not sure if this was discussed already, im looking for a code to convert datatable to dictionary without using for each loop.

@ZARA_Clark_Vincent_M
Welcome to the forum:
find starter help here:
DataTable_2Col_ToDictionary.xaml (6.5 KB)

In general it is about:
use assign
left side your dict
right side:
YourDataTableVar.AsEnumerable.ToDictionary(Of String, String)(Function (r) r(YourKeyCol).toString, Function (r) r(YourValueCol).toString)

2 Likes

thank you so much, it works. just a follow up question, if the value is a tuple, more than 1 string value, how should i edit the formula?

@ZARA_Clark_Vincent_M
are you talking about a tuple (the tuple<T> Class) or a string Array / List
however it will change the dictionary definition ToDictionary(Of String, OtherDataType)

and the value retrieval function Function (r) r(YourValueCol)

find starter help here:
DtToDict_1Key2Val_StringTuple.xaml (6.9 KB)

Hello, yes tuple…to be more specific, tuple<t1,t2>…how to change the value retrieval function…should it be Function ® r(YourValueCol1,YourValueCol2)?

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