Read entire row values one by one and add to Dictionary

Hi ,
I have excel and convert it into data table. now i just want to add all row values into one dictionary.we can add one key one value but my scenario would be read each entire row data to dictionary and then read next row data and so on,
can you please help me guys for this scenario.
Attached excel sheet here.Job.xlsx (8.9 KB)

1 Like

@sunilraju
have a look here:

in your case give a try on:

YourDataTableVar.AsEnumerable.ToDictionary(Of String, Datarow)(Function (r) r(0).toString, Function (r) r)
1 Like

Hi Thanks for quick response. Do you have any sample xaml. if yes can you please share it once.

have a look on the link above.

Yes i have seen the above xaml and you have been added 2 columns but if i add more that one column i am getting error like overloaded resolution failed because no accessible “Todictionary” accepts this number of arguments. like this if i add(dtData.AsEnumerable.ToDictionary(Of String, String)(Function (r) r(“Column1”).toString, Function (r) r(“Column2”).toString, Function (r) r(“Column3”).toString, Function (r) r(“Column4”).toString))

@sunilraju

the given requirement looks like the entire datatable should go into the dictionaray. The code / approach for this was given above with the intention:

Key1 - Row1
Key2 - Row2 etc.

the datatype for the row within the dictionary has to be of a type that can be reflected all the different columns from a row. With the benefit of the assoziative acces via col name/index the Datarow Datatype is a perfect choice.

Looking at your code sample:

  • the exception message is right: there is no method with this signature

It looks like you are trying to store each column as an entry into the dictionary (Key=Columnname). This would work for one row. For the next rows the keys will not be longer unique (and handling it with ColName_RowIndexNo is not recommended as it has not really a benefit).

So it is recommended to go for above approach for all rows = dictionary

have a look here on how to put 1 datarow into a dictionary where the column name is used for the key.

DataRow_To_Dictionary.xaml (6.7 KB)

I have ran your xaml but it was showing only one row data if i add 2more rows in data table it won’t add all rows into dictionary.
showing only one row data(i have added assign activity inside for each row but only one row data added into dictionary)

@sunilraju
yes second xaml is only adding row to the dictionary. Explanation on this and the reasons is given above

If i add multiple rows to the same dictionary?

have a look here

can we use this “ColName_RowIndexNo” in our code… because my task is to get all rows data and put it in a one dictionary

each row and each cell as an entry in the dictionary? Are you asking for this?

clolumn name is same but we have to loop through all rows and add it to dictionary

got it Bro. Now i am able to get each row data and add it to dictionary.
Thank you for your Support

Hello Raju,
In this video I have multiple examples with Dictionary:

Thanks,
Cristian Negulescu

1 Like