Solved

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

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate Unique ID in VB.NET 21 105
pressing download button in c# 7 36
ASP.NET data base connection 35 44
PowerShell: Adding ToGB to a script 4 26
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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