1,105,416 Community Members

Accessing a datatable via string variable

Member Avatar
kindofsudden
Light Poster
43 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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
Next

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

Member Avatar
Begginnerdev
Veteran Poster
1,142 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
1
 

Try This:

    Dim MyTable As String
    MyTable = "Table1"

    For i = 0 To ds.Tables(MyTable).Rows.Count - 1
        'Do Work
    Next
Member Avatar
kindofsudden
Light Poster
43 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I knew it was easy. Thanks much!

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