Solved

Filling combobox from oracle database

Posted on 2008-10-25
5
543 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
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 what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

710 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