Accessing a datatable via string variable


This is probably one of those that is so simple I can't see it. I have a string variable called Market. The variable is user chosen and is the exact same name as one of many tables in my dataset. Basically I am having the user choose which table they want in a combobox, then I want to use that variable to access the table. So if the user picks "Market1" then I want to open the table named Market1.

I am simplifying here, but need to know how to open:

For ds.<variable here>.rows.count - 1
    'perform steps

How do I inject the variable correctly? Thanks ahead of time!

Featured Replies in this Discussion


Try This:

    Dim MyTable As String
    MyTable = "Table1"

    For i = 0 To ds.Tables(MyTable).Rows.Count - 1
        'Do Work

I knew it was easy. Thanks much!

Question Answered as of 2 Years Ago by Begginnerdev
This question has already been solved: Start a new discussion instead
Start New Discussion
View similar articles that have also been tagged: