Solved

Filling combobox from oracle database

Posted on 2008-10-25
5
540 Views
Last Modified: 2013-12-18
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

0
Comment
Question by:revo1059
  • 2
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 22802971
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.
0
 
LVL 1

Author Comment

by:revo1059
ID: 22802990
I tried that,  the combobox is just empty when I do that
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 22803037
Try using a DataAdapter instead....

    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
            Dim Adapter As New OracleDataAdapter(command)
            Dim dt As New DataTable
            Adapter.Fill(dt)
            With cbStoreList
                .DataSource = dt
                .DisplayMember = dt.Columns(1).ColumnName
                .ValueMember = dt.Columns(0).ColumnName
            End With
        End Using
    End Sub

Wayne
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 22803077
wayne has a good point, the DataSource property was never set.
0
 
LVL 1

Author Closing Comment

by:revo1059
ID: 31509935
Thanks so much, I knew it was something stupid like that
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question