Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Filling combobox from oracle database

Posted on 2008-10-25
5
Medium Priority
?
551 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

722 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