Solved

Filling combobox from oracle database

Posted on 2008-10-25
5
538 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 69

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 69

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
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 shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now