Test is a datatable exists from a variable name

datatable
variable

#1

I need to create a lot of datatables on the fly.

If a datatable already exists because I already created it, I will add a row to it. If it does not exist yet, I will create it and then add a row to it.

The datatable name is a variable, which comes from another datatable. Let’s say it’s like this
strTableName = “dt” + row.Item(“int column”).toString

So it would result in this

strTableName = “dt12345”

Now I want to test if dt12345 already exists or not. I have the name, but it is inside the string variable strTableName

Any help with how I can accomplish this?


#2
  1. Create a List(Of DataTable) say listDt

  2. Check listDt.Where(Function(s) s.TableName="dt1245").Count=0

  3. Add your DataTables to it on the fly using InvokeMethod

image

image

Forgot to Add

  1. To add a row, create a tempDT variable to use for all the datatables.

tempDt = listDt.Where(Function(s) s.TableName="dt1245").First

  1. Add your rows using Add data row.

#3

Dictionary(Of string, DataTable) might be easier. Then you can directly check if it has a certain key already.


#4

Hi both

Thanks for the replies, I’m attempting to implement a solution.
I’m trying to go with the dictionary version. I run into the issue you can see in the screenshot but I will explain.

I created a dictionary variable of type <string, datatable>. I initialize it using a dummy datatable.

But I seem to not get how to add items to the dictionary using the Invoke Method activity. What should I be doing?