473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with databinding

Hi

I am new to VS.NET and C#.

I am trying to do one of the exercises in a book "Teach
Yourself Visual Studio .NET in 21 Days" and I can't
figure out what is wrong with the following code:-

private void Load_Customers()
{
SqlConnection cn = new
SqlConnection
(@"Server=
(local);DataBase=Northwind;Integrated Security=SSPI");
SqlDataAdapter da = new
SqlDataAdapter
("SELECT * FROM
Customers", cn);
DataSet ds = new DataSet
("Customers");
da.Fill(ds,"Customers");
// foreach (DataRow dr in ds.Tables
["Customers"].Rows)
// {
// MessageBox.Show(dr
["CustomerID"].ToString(), "Data",
//
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

// } This proved that I could get a
string of CustomerID's
comboBox2.DataSource = ds;
comboBox2.ValueMember
= "CustomerID"; <<<<<<<< Error here! <<<<
comboBox2.DisplayMember
= "CustomerID";
}

I'm getting an error ...

"An unhandled exception of
type 'System.ArgumentException' occurred in
system.windows.forms.dll
Additional information: Could not bind to the new display
member."

.... on the marked line. The commented out lines were put
in to prove that I could see the data on the server and
worked OK.

Any ideas! It must be simple!

TIA

Cheers

Jeff
Nov 15 '05 #1
2 4151

"Jeff Cook" <je***@aspect.co.nz> wrote in message
news:08****************************@phx.gbl...
Hi

I am new to VS.NET and C#.

I am trying to do one of the exercises in a book "Teach
Yourself Visual Studio .NET in 21 Days" and I can't
figure out what is wrong with the following code:-

My code format got screwed up - here is (hopefully) a more readable
version - at least in OE

private void Load_Customers()
{
SqlConnection cn = new SqlConnection
(@"Server=(local);DataBase=Northwind;Integrated
Security=SSPI");
SqlDataAdapter da = new SqlDataAdapter
("SELECT * FROM Customers", cn);
DataSet ds = new DataSet("Customers");
da.Fill(ds,"Customers");

// foreach (DataRow dr in ds.Tables["Customers"].Rows)
// {
// MessageBox.Show(dr["CustomerID"].ToString(), "Data",
// MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// } This proved that I could get a string of CustomerID's

comboBox2.DataSource = ds;
comboBox2.ValueMember = "CustomerID"; <<<<<<<< Error here! <<<<
comboBox2.DisplayMember = "CustomerID";
}


I'm getting an error ...

"An unhandled exception of
type 'System.ArgumentException' occurred in
system.windows.forms.dll
Additional information: Could not bind to the new display
member."

... on the marked line. The commented out lines were put
in to prove that I could see the data on the server and
worked OK.

Any ideas! It must be simple!

TIA

Cheers

Jeff

Nov 15 '05 #2
Try

comboBox2.DataSource = ds.Tables["Customers"];
comboBox2.ValueMember = "CustomerID";
comboBox2.DisplayMember = "CustomerID";

Regards
Dan Cimpoiesu

"Jeff Cook" <jeffcATaspectDOTcoDOTnz> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

"Jeff Cook" <je***@aspect.co.nz> wrote in message
news:08****************************@phx.gbl...
Hi

I am new to VS.NET and C#.

I am trying to do one of the exercises in a book "Teach
Yourself Visual Studio .NET in 21 Days" and I can't
figure out what is wrong with the following code:-


My code format got screwed up - here is (hopefully) a more readable
version - at least in OE

private void Load_Customers()
{
SqlConnection cn = new SqlConnection
(@"Server=(local);DataBase=Northwind;Integrated
Security=SSPI");
SqlDataAdapter da = new SqlDataAdapter
("SELECT * FROM Customers", cn);
DataSet ds = new DataSet("Customers");
da.Fill(ds,"Customers");

// foreach (DataRow dr in ds.Tables["Customers"].Rows)
// {
// MessageBox.Show(dr["CustomerID"].ToString(), "Data",
// MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// } This proved that I could get a string of CustomerID's

comboBox2.DataSource = ds;
comboBox2.ValueMember = "CustomerID"; <<<<<<<< Error here! <<<<
comboBox2.DisplayMember = "CustomerID";
}


I'm getting an error ...

"An unhandled exception of
type 'System.ArgumentException' occurred in
system.windows.forms.dll
Additional information: Could not bind to the new display
member."

... on the marked line. The commented out lines were put
in to prove that I could see the data on the server and
worked OK.

Any ideas! It must be simple!

TIA

Cheers

Jeff


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Richard | last post by:
Hi, I have a DateTime picker control on a form. The datetime picker control is data bound to a column in a DataTable. Yes I know about bound DateTime pickers and DBNull and etc. so no troubles...
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
2
by: wolfgang wagner | last post by:
hi all! im trying to edit data in a datagrid (like described here: http://aspnet.4guysfromrolla.com/articles/071002-1.aspx) but if i click the edit button i get the following error invalid...
0
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
0
by: s.gregory | last post by:
My page layout is like this: Page >DataList (databound using ObjectDataSource1 contained in page) >>Items >>>UserControl >>>>GridView (databound using another ObjectDataSource2 contained in...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
2
by: Kalpesh | last post by:
Hello, I am facing a design problem here & need your expert design advice on this. Scenario: I have a class called Vendor - which has several simple attributes like Name, Address etc Now,...
1
by: m_mohanna | last post by:
I've problem with databinding in vb.net The problem that i'm trying to set a text field of the databinding programmatically during runtime, the change appears on the form, but after save the new...
7
by: Vlado Jasovic | last post by:
Hello, I'm using typed dataset for databinding to windows controls and I'm having some problems. I'm trying to move all business logic to datatable column_changing events and the problem that...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello to all, I want to know if DataBinding in asp.net 2,0 is better than to fill up the values of the controls of the following form: this.miControlTextBox.Text = valorParaControlTextbox; ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.