How to populate in combo drop down list

ellen

Member
Joined
Aug 20, 2005
Messages
6
Programming Experience
Beginner
Hi everyone,

I have CountryDataSet1 DataSet created and click on combo drop down list properties. I add CountryDataSet1 to data source and country.Country to Display Member.

so i run program and click on combo drop down list and see if items in combo can be displayed but nothing appears..

how to populate data in combo drop down list from ms access?

Codes here are :

Private Sub PopulateCountryCombo()



Dim cnSQL As OleDbConnection

Dim cmdSQL As OleDbCommand

Dim drSQL As OleDbDataReader

Dim strSQL As String

strSQL = "select Country from country"

cnSQL =
New OleDbConnection(ConnectionString)

cnSQL.Open()

cmdSQL =
New OleDbCommand(strSQL, cnSQL)

' Use ExecuteReader if select only

drSQL = cmdSQL.ExecuteReader()

cboCountry.Items.Clear()

'Loop through the result set and add the country to

' the combo box

Dim oRow As DataRow

Do While drSQL.Read()
oRow =
New DataRow(drSQL.Item("Country").ToString()) --> error display Protected New..so how to resolve it? and am i codings correcting to populate data from ms access in combo drop down list?

cboCountry.Items.Add(oRow)

Loop

' Close and Clean up objects
drSQL.Close()

cnSQL.Close()

cmdSQL.Dispose()

cnSQL.Dispose()

End Sub



regards
ellen
 
Last edited:
How to populate data in combo drop down list from ms access

hi sir.

i try different codes to populate data in combo drop down list but still cannot work!

my next codes are

Private Sub PopulateIndustryCombo()

Dim cnSQL As OleDbConnection

Dim cmdSQL As OleDbCommand

Dim strSQL As String

Dim drSQL As OleDbDataReader

Dim strRow As String

strSQL = "select Industry from industry"

cnSQL =
New OleDbConnection

cnSQL.Open()

cmdSQL =
New OleDbCommand(strSQL, cnSQL)

drSQL = cmdSQL.ExecuteReader()

Do While (drSQL.Read())

strRow = drSQL.Item("Industry").ToString)

cboIndustry.Items.Add(strRow)

Loop

End Sub

pls help

 
As always, in .NET there are many different ways to do what you want. It seems that you are confusing several of them. Your question mentions the CountryDataSet1 dataset, yet there is no such dataset in your code.
Read here about using the DataSet or DataReader class.
If you want to add the items using a dataReader, there's no need to create a new dataRow, just add the string value to the comboBox.
Also, for winforms, It's called a comboBox, for WebForms it's called a dropDownList. Try not to confuse those as well.
 
Back
Top