Home All Groups Group Topic Archive Search About
Author
29 Nov 2006 3:20 PM
HLong
Hi, I am trying to setup an App to access and edit data on the Northwind
database.  I have a DataGridView, a BindingNavigator, a DataSet and a
BindingSource on a form. On load, I set the BindingSource.DataSource=DataSet,
then BindingNavigator.BindingSource=Me.BindingSource and the
DataGridView.DataSource=Me.BindingSource. Tables are loaded to the DataSet as
their names is selected from a ComboBox. Up to here everything works fine,
the only thing I have to do to sync everything is to set the DataMember of
the BindingSource to the name of the table selected.

HERE IS THE PROBLEM

If I add some TextBoxes and bind them to the selected table,
Me.txtEmployeeID.DataBindings.Add("Text", Me.BindingSource, "EmployeeID"), it
works fine.  Everything still in sync.  However, as soon as I select another
table I get an error:

"Cannot bind to the property or column EmployeeID on the DataSource.
Parameter name: dataMember"

Can someone explain what is happening? Does this mean that I need a
BindingSource for each table? Why it works for the BindingNavigator and not
for DataBindings? What would be the best approach?  Thank you for any help.

Author
30 Nov 2006 10:32 PM
Earl
The short answer is yes, you need a binding source for each table. Think
about what is happening in your situation -- you bind your textbox to a
certain column out of a certain table and then you change the table! I'd be
more upset if it didn't throw an error over that ...

Show quote
"HLong" <HL***@discussions.microsoft.com> wrote in message
news:DE6B7B11-177A-4910-9621-B1F8508EEA01@microsoft.com...
> Hi, I am trying to setup an App to access and edit data on the Northwind
> database.  I have a DataGridView, a BindingNavigator, a DataSet and a
> BindingSource on a form. On load, I set the
> BindingSource.DataSource=DataSet,
> then BindingNavigator.BindingSource=Me.BindingSource and the
> DataGridView.DataSource=Me.BindingSource. Tables are loaded to the DataSet
> as
> their names is selected from a ComboBox. Up to here everything works fine,
> the only thing I have to do to sync everything is to set the DataMember of
> the BindingSource to the name of the table selected.
>
> HERE IS THE PROBLEM
>
> If I add some TextBoxes and bind them to the selected table,
> Me.txtEmployeeID.DataBindings.Add("Text", Me.BindingSource, "EmployeeID"),
> it
> works fine.  Everything still in sync.  However, as soon as I select
> another
> table I get an error:
>
> "Cannot bind to the property or column EmployeeID on the DataSource.
> Parameter name: dataMember"
>
> Can someone explain what is happening? Does this mean that I need a
> BindingSource for each table? Why it works for the BindingNavigator and
> not
> for DataBindings? What would be the best approach?  Thank you for any
> help.
Author
1 Dec 2006 2:07 PM
HLong
Thanks Earl,
I am new to this and I am trying to understand what is best way to do this. 
Ok, this means then that when you bind a property to a column on
BindingSource, the BindingSource keeps a list of all these bindings while it
exists and if you change the DataMember, you break this.  Fine, it makes
sence.  Now, is there a way of clearing these bindings, if I want to change
the DataMember?  I am trying to access and edit say three tables with same
Navigator, TabControl, BindingSource and DataGrid on a single form.  Is it
possible or completly stupid? Please be honest.

Show quote
"Earl" wrote:

> The short answer is yes, you need a binding source for each table. Think
> about what is happening in your situation -- you bind your textbox to a
> certain column out of a certain table and then you change the table! I'd be
> more upset if it didn't throw an error over that ...

AddThis Social Bookmark Button