Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i m using following code & get the error.
"Cannot bind to the new display member."
in which i m having 2 radiobutton & 1 combobox and 1 button
C#
private void btnshow_Click(object sender, EventArgs e)
{
    panel1.Visible = false;
    if (rbparty.Checked == true)
    {
        panel1.Visible = true;
        fetchParty();
        //comboBox1.DisplayMember = "Table.P_Namee";
        //comboBox1.ValueMember = "P_Name";
        MessageBox.Show(rbparty.Text);
    }
    if (rbProduct.Checked == true)
    {
        panel1.Visible = true;
        fetchProduct();
        //comboBox1.DisplayMember = "Table.Prod_Name";
        //comboBox1.ValueMember = "Prod_Name";
        MessageBox.Show(rbProduct.Text);
    }
}

public void fetchProduct()
        {
            comboBox1.DisplayMember = "";
            da = new SqlDataAdapter("Select Prod_Name from tblProdMaster", con);
            DataSet ds = new DataSet();
            comboBox1.DataSource = ds;
            da.Fill(ds);
            comboBox1.DisplayMember = "Table.Prod_Name";
            comboBox1.ValueMember = "Prod_Name";


        }
        public void fetchParty()
        {
            comboBox1.DisplayMember = "";
            da = new SqlDataAdapter("Select P_Name from tblPartyMaster", con);
            DataSet ds1 = new DataSet();
            da.Fill(ds1);
            comboBox1.DataSource = ds1;
            comboBox1.DisplayMember = "Table.P_Namee";
            comboBox1.ValueMember = "P_Name";
        }

can anyone help me pls.?
THANKS IN ADVANCE
Posted
Updated 3-May-16 18:57pm
v2
Comments
Toniyo Jackson 15-Dec-10 5:18am    
Always write your code inside code block

Just remove the comboBox1.DisplayMember = ""; and replace Table.P_Namee" with P_Name".

Try this,
public void fetchProduct()
        {
            da = new SqlDataAdapter("Select Prod_Name from tblProdMaster", con);
            DataSet ds = new DataSet();
            comboBox1.DataSource = ds;
            da.Fill(ds);
            comboBox1.DisplayMember = "Prod_Name";
            comboBox1.ValueMember = "Prod_Name";


        }
        public void fetchParty()
        {
            da = new SqlDataAdapter("Select P_Name from tblPartyMaster", con);
            DataSet ds1 = new DataSet();
            da.Fill(ds1);
            comboBox1.DataSource = ds1;
            comboBox1.DisplayMember = "P_Name";
            comboBox1.ValueMember = "P_Name";
        }
 
Share this answer
 
v2
I know this is an old post, but I ran into this problem and none of the suggestions were helpful. As it turns out, I ran into a variation of the problem...

I have 3 combo boxes on one screen, and they are cascaded such that something must be selected in the first box in order to activate and populate the 2nd box. Similarly, the 3rd box is only activated and populated when the 2nd box has a selection.

On initial load of my screen, I kept getting an error thrown when I tried to set the value member in the first box. Everything about that first box was perfect, and the other boxes had their data elements set up properly as well.

As it turns out, one of the selections in the 1st combo box did not have any data to display in the 2nd combo box. When this happened, my code was trying to set the ValueMember for the 2nd combo box when there was no data in the DataSource. This is what caused the "could not bind..." error for me. Several hours of debugging to find this, but the fix was a simple "if" statement to not set the ValueMember for the combo box when there was no data.
 
Share this answer
 
I HAVE FACE SAME PROBLEM AND SEARCHED FOR THE SOLUTIONS ON MANY SITES, BUT THE SOLUTION I FOUND WAS VERY SIMPLE.

WHILE BINDING DATASOURCE TO COMBOBOX, ALSO ADD TABLE REFERENCE TO IT. BELOW IS MY CODE TO LOAD COMBOBOX FROM A STORED PROCEDURE.

Dim cnBusBr As New SqlConnection(GetConnectionString("BuzzConnection"))
Dim cmBusBr As New SqlCommand
Dim daBusBr As New SqlDataAdapter

With cmBusBr
.Connection = cnBusBr
.CommandType = CommandType.StoredProcedure
.CommandText = "spBusinessBranches"
End With
HandleConnection(cnBusBr)

daBusBr.SelectCommand = cmBusBr
Dim dsBusBr As New DataSet
daBusBr.Fill(dsBusBr)
ctrl.DataSource = dsBusBr.Tables(0)
ctrl.DisplayMember = "BBNAME"
ctrl.ValueMember = "BBID"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900