Use a cell value to select a datatable

Hi there,

I’m facing a problem, In the begining of my program I create several empty datatables (the columns are not the same).

Example for 1 dt :


I loop throught an excel file (cfg) containing mainly paths and sheetnames.

Most part of my code is in a for each loop (for each row in cfg), using the cfg row variables.

I added a column in this excel file to indicate the dataTable to work with. :


So in the activities needing the datatable I tried to pass the name of the datatable in the cfg :

But I get the message cannot convert String to Datatable.

Is there any simple way to indicate that this row refers to the datatable created in the begining (name of the created datatable is the same as in the excel file)

Thanks in advance,

You can’t convert a string to a variable name. If you want to use a string to identify a datatable, you need to create a translation table/dictionary. E.g. you could create a dictionary with the name as key and the datatable variable as value:

dicTables = New Dictionary(Of String, DataTable)

Add all your datatable variables to the dictionary:

dicTables("dt1") = dt1
dicTables("dt2") = dt2
dicTables("DataReportingAssurimo") = DataReportingAssurimo

After that you can access any datatable in the dictionary using a string like this:

1 Like

Thanks !

Can’t try it now but this should work :slight_smile:

1 Like

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