Solved

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

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

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

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…
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

21 Experts available now in Live!

Get 1:1 Help Now