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
Solved

Populating a combobox with values from SQL database

Posted on 2010-11-14
1
286 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…

860 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