Results 1 to 9 of 9

Thread: [2005] Choosing Tables

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    45

    [2005] Choosing Tables

    Hi,
    How u make that all your table come in a combobox and you can select your table and then the data from that table loads into the datagrid and u can change it...

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Choosing Tables

    That would depend on the backend database. They all store the metadata in different areas for you to find.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Choosing Tables

    As Gary mentioned, what database are you using?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    45

    Re: [2005] Choosing Tables

    an ms access

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

    Re: [2005] Choosing Tables

    vb.net Code:
    1. Dim table As DataTable
    2.  
    3. Using connection As New OleDbConnection("connection string here")
    4.     connection.Open()
    5.     table = connection.GetSchema("TABLES")
    6. End Using
    7.  
    8. myComboBox.DisplayMember = "TABLE_NAME"
    9. myComboBox.DataSource = table
    Thos enames work in SQL Server and I think they're the same in Access. If not you can just do little testing to get the right collection and column names.
    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

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    45

    Re: [2005] Choosing Tables

    well this doesnt set the databases automatic in the combo list if i see good

  7. #7
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: [2005] Choosing Tables

    This code will load the combo box with the names of the data tables and not the schema tables such as MSysAccessObjects, MSysACEs, MSysObjects, MSysQueries and MSysRelationships if that is what you are looking for from an Access data base.

    vb Code:
    1. Private Sub btnLoadComboBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadComboBox1.Click
    2.     ' Returns schema information for the data source (Data Base)
    3.     Dim restrictions() As String = {Nothing, Nothing, Nothing, "TABLE"}
    4.     Dim table As DataTable
    5.     Using connection As New OleDbConnection("connection string")
    6.         connection.Open()
    7.         table = connection.GetSchema("TABLES", restrictions)
    8.     End Using
    9.     For Each dr As DataRow In table.Rows
    10.         Me.cboLoadComboBox1.Items.Add(dr("TABLE_NAME"))
    11.         Me.cboLoadComboBox1.SelectedIndex = 0
    12.         Me.cboLoadComboBox1.Sorted = True
    13.     Next
    14. End Sub
    Last edited by CoachBarker; Aug 28th, 2008 at 02:00 PM.
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Choosing Tables

    Please do not post duplicate threads.

    Dup Thread Deleted
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: [2005] Choosing Tables

    What does not work??? You have to be more specific.

    Add a new form to a project
    Add a combo box to the form and call it cboLoadComboBox1
    Add a button to the form and call it btnLoadComboBox1
    In design view double click on the button and copy and past this part of the code into the button click event

    vb Code:
    1. ' Returns schema information for the data source (Data Base)
    2.     Dim restrictions() As String = {Nothing, Nothing, Nothing, "TABLE"}
    3.     Dim table As DataTable
    4.     Using connection As New OleDbConnection("connection string")
    5.         connection.Open()
    6.         table = connection.GetSchema("TABLES", restrictions)
    7.     End Using
    8.     For Each dr As DataRow In table.Rows
    9.         Me.cboLoadComboBox1.Items.Add(dr("TABLE_NAME"))
    10.         Me.cboLoadComboBox1.SelectedIndex = 0
    11.         Me.cboLoadComboBox1.Sorted = True
    12.     Next

    don't forget to add your connection string and it will load the name of the tables in the database.
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

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