I’m getting this error: Cannot bind to the new display member C#
sConn = new SqlConnection(sStr);
daSched = new SqlDataAdapter("Select Subject from Schedules where Username = '" + lblUsername.Text + "'", sConn);
dsSched = new DataSet();
daSched.Fill(dsSched, "Schedules");
dsSched.Tables["Schedules"].PrimaryKey = new DataColumn[] { dsSched.Tables["Schedules"].Columns["ScheduleID"] };
cbxSubject.DataSource = dsSched.Tables["Schedules"];
cbxSubject.DisplayMember = "Schedule";
cbxSubject.ValueMember = "ScheduleID";
cbxSubject.Text = "Choose Subject";
I don’t know where went wrong. This is the preview of the table Schedules: http://i47.tinypic.com/1zzoz5z.png
Thanks for any help.
You don’t have a field in your table called “Schedule”, so there is no member the control can find called Schedule, and you have selected only Subject
ScheduleID is already your primary key, so you’re better of changing your Sql Query to:
Select ScheduleID, Subject From… (also you probably should parameterize it)This line ->
dsSched.Tables["Schedules"].PrimaryKey = new DataColumn[] { dsSched.Tables["Schedules"].Columns["ScheduleID"] };is unnecessary.From what I can tell I beleive you want your display member to be the “Subject”
Also – you should Open your connection (I don’t see it in your post) – and more ideally wrap it in a using statement
Something like: