|
-
Jul 29th, 2007, 03:01 PM
#1
Thread Starter
New Member
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.
-
Jul 30th, 2007, 07:47 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|