Solved

canot bind to new display member

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.

734 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