Database
  Home arrow Database arrow Page 2 - Working With ADOX and Combo Box Control
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

Working With ADOX and Combo Box Control
By: Mohammed Qattan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2004-09-21

    Table of Contents:
  • Working With ADOX and Combo Box Control
  • Code
  • Using Combo Box Control
  • Employee Form
  • More on Combo Box

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working With ADOX and Combo Box Control - Code


    (Page 2 of 5 )

    After you download the project files, you will find out that we have a single form which has the following:

    • Two Labels with captions of “Tables” and “Table Keys”.
    • Two List Boxes:

          - lstTables: which will have all the Tables available in the database specified in the connection string.
          - lstKeys: when a user selects a table from the “lstTable”, the lstKeys will be filled with the Keys specified for the table (in the database for sure)

    Design Consideration:

    1. We need a connection to the data source, and we need an instance of the ADOX. They will be made available as private variables for the class, in our case, the form.

    2. In the “Load”  event of the form, we will initialize the variables; please make sure to update the connection string.

    3. We need to ensure that we have a reference to the ADO, and the ADOX COM components:

    a. MSADO
    b. MSADOX

    Note: The dll’s are usually available on “C:\Program Files\Common Files\System\ado”

    So, let's now have a look at the code, first of all the code that loads the tables available in the system, but we don’t want to list the System tables.

    '======================================
        ' This Sub will fill the lstTables with the table names for

    the Database specified in the connection String
        '======================================
        Private Sub FillTablesList()
            Dim oTable As ADOX.Table
            For Each oTable In oDatabase.Tables
                If oTable.Type = "TABLE" Then
                    lstTables.Items.Add(oTable.Name)
                End If
            Next
        End Sub

    As you can tell, we checked the type of the table to be “Table”, the type may have another two values, “SYSTEM TABLE”, and “GLOBAL TEMPORARY”.

    And here is the code that will list the keys when a user selects a certain table.

    '======================================
        ' This Sub will fill the lstKeys with the name of the Keys for

    the table selected by the user.
        '======================================
        Private Sub lstTables_SelectedIndexChanged(ByVal sender As

    System.Object, ByVal e As System.EventArgs) Handles

    lstTables.SelectedIndexChanged
            Dim oTable As ADOX.Table
            Dim oKey As ADOX.Key

            oTable = oDatabase.Tables(lstTables.SelectedItem)
            lstKeys.Items.Clear()
            For Each oKey In oTable.Keys
                lstKeys.Items.Add(oKey.Name)
            Next

        End Sub

    Note that we are looping through all the keys in the table. Since a table may not only have one key, besides, foreign keys, and unique keys are included in the collection.

    As we mentioned at the beginning of the article. This is only the first step for a great tool. We can mention some of the big tools that can be based on this great component:

    1) Code Generators: as a matter of fact, we do really care about the tables, columns, and all the available information about the database to make our data access tier. And from our data access tier we can make the business tier.

    2) Database management tools: with more work, you can play with the tables. If you are not so comfortable with the database management tool you already have, or if your database vendor didn’t supply one, or you would like to add new functionality that is not available to your software, then you now know how to make things brighter.

    And I will leave the list open for your preference.

    Happy programming to all.

    More Database Articles
    More By Mohammed Qattan


     

    DATABASE ARTICLES

    - Excel Reference
    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT