revo1059
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
ASKER
I tried that, the combobox is just empty when I do that
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
wayne has a good point, the DataSource property was never set.
ASKER
Thanks so much, I knew it was something stupid like that
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.