Link to home
Start Free TrialLog in
Avatar of revo1059
revo1059Flag for United States of America

asked on

Filling combobox from oracle database

I am trying to fill a combobox from a database.  I Want the ID to the be the ValueMember and the NAME to be the DisplayMember.  The code below just adds however many rows the query finds, but they do not display any data.
Private Sub FillStoreList()
        Dim connectionString As String = GetConnectionString()
        Dim queryString As String = _
         "SELECT ID, NAME FROM CURRENCY ORDER BY NAME"
 
        Using connection As New OracleConnection(connectionString)
            Dim command As OracleCommand = connection.CreateCommand()
            command.CommandText = queryString
            Try
                connection.Open()
                Dim dataReader As OracleDataReader = _
                 command.ExecuteReader()
                While dataReader.Read()
                    '                    cbStoreList.Items.Add("")
                    cbStoreList.DisplayMember = dataReader(1)
                    cbStoreList.ValueMember = dataReader(0)
                    cbStoreList.Items.Add("")
 
                End While
                dataReader.Close()
 
            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try
        End Using
 
    End Sub

Open in new window

Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

if you find a combo (that means using DisplayMember and ValueMember) you don't need to loop through your datasource to add them one line at a time.

have you tried:

                Dim dataReader As OracleDataReader = command.ExecuteReader()
                    cbStoreList.DisplayMember = dataReader(1)
                    cbStoreList.ValueMember = dataReader(0)
 
I am not sure that a DataReader can be used as input for a combo.
Avatar of revo1059

ASKER

I tried that,  the combobox is just empty when I do that
ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
wayne has a good point, the DataSource property was never set.
Thanks so much, I knew it was something stupid like that