Results 1 to 2 of 2

Thread: ComboBox to display to list from DB table

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    8

    Question ComboBox to display to list from DB table

    Hello Guys,

    Please, please can anyone help. I seem to be stuck with a problem, I have created tables in SQL Server 2005 Express with the following definitions:

    Customer
    [Customer ID]
    [NAME] nvarchar(100),
    [CONTACT_NAME] nvarchar(60),
    [CONTACT_1] nvarchar(100),
    [CONTACT_2] nvarchar(50),
    [CITY_TOWN] nvarchar(70),
    [PROVINCE] varchar(50),
    [COUNTRY] varchar(100)

    Country
    [COUNTRY NAME]
    [City]

    I have created a user-interface with Visual Basic Express 2005. So what steps do I use to link a CountryComboBox on the user-interface form to the table - Country [COUNTRY NAME]? So that the CountryComboBox can display the list of countries from the - database table - Country for the user. Thanks a lot.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ComboBox to display to list from DB table

    Code:
    Dim sSQL As String
            sSQL = "SELECT [country name] FROM yourtable "
            sSQL = sSQL & "ORDER BY [country name] "
            Dim command As New SqlCommand(sSQL, myConnection)
            Dim reader As SqlDataReader = command.ExecuteReader()
            While reader.Read()
                cboCountry.Items.Add(reader.GetString(0) 
            End While
            reader.Close()
    myConnection is used to connect to my database. Replace that with your connection object. Also replace yourtable with the name of your database table that holds the countries.

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