Solved

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

Posted on 2014-01-22
3
265 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
[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
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 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