J
Jeff Cook
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
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