Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

combo box and sqlclient

Posted on 2004-08-18
8
Medium Priority
?
338 Views
Last Modified: 2011-09-20
Hi,
I use SQL DataReader to get data from sql then add to combo box:

cboTest.Items.Add("xxx")
With this way, I just can set the display member of the box, but cannot set the value inside. Anyone can help?

Another way: Set DataSource property of combo box to a table of dataset.

Could you tell me the faster way to write this ? Or another way?
Thanks, PN.
0
Comment
Question by:phuongnguyen
[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
  • 5
8 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11829489
try something like this

Dim MyList as new sortedList

Do while myReader.Read
     dim strItem as string
     dim strItemID as string
     strItem = myReader("yourItem").ToString
     strItemID = myReader("yourItemID").ToString
     idList.Add(strItemID, strItem)
Loop

Now, bind the sortedlist to the combobox

cbotest.DataSource = idList
cbotest.DisplayMember = idlist.value
cbotest.ValueMemeber = idlist.key
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11829891
sorry, this should be correct

Dim MyList as new sortedList

Do while myReader.Read
     dim strItem as string
     dim strItemID as string
     strItem = myReader("yourItem").ToString
     strItemID = myReader("yourItemID").ToString
     Mylist.Add(strItemID, strItem)
Loop

Now, bind the sortedlist to the combobox
cbotest.DataSource = Mylist
cbotest.DisplayMember = Mylist.value
cbotest.ValueMemeber = Mylistlist.key
0
 
LVL 7

Expert Comment

by:ramesh12
ID: 11831805
Cant we set the datasource of combo box to a SqlDataReader
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11838668
Not directly, only the way you tried or like my way
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11838675
Otherwise use a datatable or dataset they can directly be used as a datasource
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 400 total points
ID: 11842824
Forget my previous suggestion this is the way to go

        Dim myList As New ArrayList

        While myReader.Read()
            myPeople.Add(New DictionaryEntry(myReader("yourid"), myReader("youritem")))
        End While

        Me.ComboBox1.DataSource = myList
        Me.ComboBox1.DisplayMember = "Value"
        Me.ComboBox1.ValueMember = "Key"

to get the information from the combobox use

        Dim myThing As DictionaryEntry = Me.ComboBox1.SelectedItem
        MessageBox.Show(mything.Key & " - " & mything.Value)

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 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