Solved

canot bind to new display member

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

20 Experts available now in Live!

Get 1:1 Help Now