Results 1 to 3 of 3

Thread: Choose datatables with combobox and display data in datagridview

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Location
    Belgrade, Serbia, Europe
    Posts
    15

    Unhappy Choose datatables with combobox and display data in datagridview

    Any idea, how to choose data tables with combo box and display data in data grid view?
    I have 80 tables in database, and i need to have combo box which will be populated with data table names,
    when i select certain data table i expect to that specific table populate data grid view.

    any solutions?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Choose datatables with combobox and display data in datagridview

    Follow the CodeBank link in my signature and check out my thread on Getting Schema Information. It shows how to get various schema information using the appropriate DbConnection object. Once you have a DataTable containing the schema information for your tables, you can bind it to a ComboBox in the normal way. When the user makes a selection, get the table name from the Text property and insert that into a SQL Select statement and use that to query the database as you normally would. I've also got a thread in the CodeBank about Retrieving & Saving Data if you need help on that part.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Choose datatables with combobox and display data in datagridview

    Sorry, I think that thread about getting schema info is one that I intended to write but never got around to. This is for SQL Server but will be very similar for other databases:
    Code:
    Using connection As New SqlConnection("connection string here")
        connection.Open()
    
        Dim table = connection.GetSchema("Tables")
    
        With ComboBox1
            .DisplayMember = "TABLE_NAME"
            .DataSource = table
        End With
    End Using
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width