Solved

Populating a combobox with values from SQL database

Posted on 2010-11-14
1
283 Views
Last Modified: 2012-05-10
I need to populate a combobox with values from a dataset. When running the code below, I recieve "Cannot bind to the new display member.Parameter name: newDisplayMember". Any suggestions?

        DAL rating = new DAL();
        DataSet ds = rating.getRatings("SELECT * FROM tblRating");
        cboRating.DataSource = ds;
        cboRating.DisplayMember = "Rating"; //Colunm name for display
        cboRating.ValueMember = "RatingID"; //Primary key <----Error here
0
Comment
Question by:98fatboyrider
1 Comment
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 34132618
DataSets usually contain DataTables, and it is usually the DataTable that you bind to.

Try:

        cboRating.DisplayMember = "Rating"; //Colunm name for display
        cboRating.ValueMember = "RatingID"; //Primary key

        cboRating.DataSource = ds.Tables[0];

Open in new window


If that doesn't work then check to make sure that you are pulling back a column named "RatingID".
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

18 Experts available now in Live!

Get 1:1 Help Now