We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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
Next

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

2
Contributors
2
Replies
20 Hours
Discussion Span
5 Months Ago
Last Updated
3
Views
Question
Answered
kindofsudden
Light Poster
38 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Try This:

    Dim MyTable As String
    MyTable = "Table1"

    For i = 0 To ds.Tables(MyTable).Rows.Count - 1
        'Do Work
    Next
Begginnerdev
Practically a Posting Shark
864 posts since Apr 2010
Reputation Points: 184
Solved Threads: 142
Skill Endorsements: 8

I knew it was easy. Thanks much!

kindofsudden
Light Poster
38 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Months Ago by Begginnerdev

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0806 seconds using 2.71MB