Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I have a combobox and i m populating it from DB
Like this,i called it in load event
Categorycls c = new Categorycls();
 comboBox1.DataSource = c.GetCategories();
  comboBox1.DisplayMember= "Category Description";
   comboBox1.ValueMember = "CatID";


and GetCategories is as
public DataSet GetCategories()
        {
            d = new DBConnection();
            d.OpenConn();
            select = new OleDbCommand();
            select.CommandText = "Select * from [Categories]";
            select.Connection = d.getConnection();
            adapter = new OleDbDataAdapter(select);
            adapter.Fill(ds, "Categories");
            return ds;
        }

the problem is arising that on load it displays and error "cannot bind to new display member.
Parameter name: newDisplayMember
The column names are same as of DB
Can any one tell the reason and solution?
Regards
Posted
Comments
Syed Salman Raza Zaidi 6-Jun-11 4:04am    
The DB is access 2007
Tarun.K.S 6-Jun-11 4:08am    
Can you also post your database table structure as I think the DisplayMember is not set to the correct column.

1 solution

The Problem is your getting catefoiries in Dataset and the Combobox is accepted only in table.

Try this line
MIDL
Categorycls c = new Categorycls();
 comboBox1.DataSource = c.GetCategories().Tables[0];
  comboBox1.DisplayMember= "Category Description";
   comboBox1.ValueMember = "CatID";
 
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