Solved

canot bind to new display member

Posted on 2009-05-19
2
207 Views
Last Modified: 2012-05-07
Hi experts
I am writing c# stand alone appln,in which i'm using acombobox to populate data from mysql database.
i'm able to connect to database, but at run time i'm getting the error  canot bind to new display member
pls helpme
private void Form1_Load(object sender, EventArgs e)

        {

           

            string connString = @"server=localhost;database=abc;user id=root;password=kodanda;";

            string sql = @"select client_mst.client_id as id,Concat(client_no,'   ' ,client_name) as client from client_mst";

            conn = null;
 

            try

            {

                conn = new MySqlConnection(connString);

                conn.Open();
 

                 dAdapter1 = new MySqlDataAdapter(sql, conn);

                MySqlCommandBuilder cBuilder = new MySqlCommandBuilder(dAdapter1);

                ds = new DataSet();

                dAdapter1.Fill(ds);

                bSource = new BindingSource();

                bSource.DataSource = ds;

                clNamecomboBox.DataSource = bSource;

                MessageBox.Show(conn.Database);

                

                clNamecomboBox.ValueMember = "id";

                clNamecomboBox.DisplayMember = "client";
 

            }

            catch (Exception ex)

            {

                MessageBox.Show("Error"+ex);

            }

        }

Open in new window

0
Comment
Question by:APPIREDDY
  • 2
2 Comments
 
LVL 13

Expert Comment

by:kaylanreilor
ID: 24422862
bSource.DataSource = ds;
is not good.
I would write something like this:
ds = new DataSet();

dAdapter1.Fill(ds, "myTable");

bSource = new BindingSource();

bSource.DataSource = ds.Tables["myTable"];

Open in new window

0
 
LVL 13

Accepted Solution

by:
kaylanreilor earned 500 total points
ID: 24422917
BTW, I told you in the other thread that the DataSet can "host" several tables.
I see here that you have a DataAdapter named dAdapter1. So if you have later a dAdapter2 that deals with another table of your DB, you should take the oportunity to reuse your DataSet. Perhaps the DataSet can be a member of your class (depending on your design needs).
Then you will certainly write:
dAdapter1.Fill(ds, "myTable1");
dAdapter2.Fill(ds, "myTable2");
And you don't need to give the tables in your dataset the same name that the real table have in your DB.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

930 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

12 Experts available now in Live!

Get 1:1 Help Now