?
Solved

canot bind to new display member

Posted on 2009-05-19
2
Medium Priority
?
246 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
[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
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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

718 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