Results 1 to 3 of 3

Thread: How to populate in combo drop down list

  1. #1
    ellen is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Aug 2005
    Posts
    6
    Reputation
    0

    How to populate in combo drop down list

    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 :

    PrivateSub PopulateCountryCombo()



    Dim cnSQL As OleDbConnection

    Dim cmdSQL As OleDbCommand

    Dim drSQL As OleDbDataReader

    Dim strSQL AsString

    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

    DoWhile 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()

    EndSub



    regards
    ellen
    Last edited by ellen; 08-21-2005 at 3:21 AM.

  2. #2
    ellen is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Aug 2005
    Posts
    6
    Reputation
    0

    Unhappy 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

    PrivateSub PopulateIndustryCombo()

    Dim cnSQL As OleDbConnection

    Dim cmdSQL As OleDbCommand

    Dim strSQL AsString

    Dim drSQL As OleDbDataReader

    Dim strRow AsString

    strSQL = "select Industry from industry"

    cnSQL =
    New OleDbConnection

    cnSQL.Open()

    cmdSQL =
    New OleDbCommand(strSQL, cnSQL)

    drSQL = cmdSQL.ExecuteReader()

    DoWhile (drSQL.Read())

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

    cboIndustry.Items.Add(strRow)

    Loop

    EndSub

    pls help


  3. #3
    Paszt's Avatar
    Paszt is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Raleigh, NC - USA
    Posts
    1,502
    Reputation
    308
    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.
    — Stephen Paszt

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking