Solved

canot bind to new display member

Posted on 2009-05-19
2
219 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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