Solved

What combobox property must be filled to make a choosen option reflect  a correspondent code?

Posted on 2014-01-22
3
263 Views
Last Modified: 2014-01-22
Hi Experts!

What combobox property must be filled to make a choosen option reflect  a correspondent code?

Example:

Combo:
01
BD table:
02

The code I used:

.....
 using (var connection = new MySqlConnection(connectionString))
            {
                connection.Open();
                var query = "SELECT SB_CR, DESCRICAO FROM cr WHERE TIPO=1";
                using (var command = new MySqlCommand(query, connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        //Iterate through the rows and add it to the combobox's items
                        while (reader.Read())
                        {
                            comboBox1.Items.Add(reader.GetString("DESCRICAO"));

                           // It doesn't work
                           //comboBox1.ValueMember = reader.GetString("SB_CR");

                        }
                    }
                }

Open in new window


So If I choose CASA a correspondent property containing the PK  101 must be available to be used by the program. What's the property ?


Thanks in advance!
0
Comment
Question by:Eduardo Fuerte
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39799868
ValueMember and DisplayMember are used for databinding your combo box to a datasource, such as a DataSet.

If you want to use a SQLDataReader, you will need to create a ComboBoxItem, set its Content and Tag properties and then add it to your ComboBox.
0
 

Author Comment

by:Eduardo Fuerte
ID: 39800284
Hello

Really much easier using Dataset than code as I did.
I had only to turn off constraints in dataset for my particular purpose.
and simply use

  var teste1 = this.comboBox1.SelectedValue;
0
 

Author Closing Comment

by:Eduardo Fuerte
ID: 39800864
Ok
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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