BindingSource, DataSet and multiple tables not syncing


Flomo Togba Kwele

I have defined a dataset using the DataSource Configuration Wizard. I
dropped 3 tables onto the design surface. It looks like this:

Tbl1 Tbl2 Tbl3
FK========> PK

Table 1 is a Client, tbl2 is a Person and 3 is an Address.
There is only one Person for a Client and only one Address for a

When I look at the relations the designer created, it says that for
the Client-Person relation, the Person is the parent and the child is
the Client. The relation editor will not allow me to change this.

I created a bindingsource for the client. I set its datasource
property to the dataset and table Client to the DataMember property. I
created another bindingsource, PersonBindingSource, and set is
datasource to the dataset and the Person table to the DataMember
property. Finally I created an Address bindingsource and set its
datasource to the dataset and its Address table to the DataMember

I used a bindingnavigator. When I move from row to row with the
navigator, only those controls bound to the client binding source
reflect the navigation. The controls bound to either the Person or
Address do not.

I must be missing something basic. Can someone please help?



For the children, you need to bind them to the data relation with the
parent table instead of the child table. Then when you move through the
records of the parent, the children will change as well.

Here's an example that runs against Northwind using the
Customers and Orders tables.

* Dim ds as CustomersDataSet = CustomersDataSet.GetCustomers()
* m_CustomersBindingSource.DataSource = ds
* m_CustomersBindingSource.DataMember = "Customers"
* m_CustomersGrid.DataSource = m_CustomersBindingSource
* m_ChildOrdersBindingSource.DataSource = m_CustomersBindingSource
* m_ChildOrdersBindingSource.DataMember = "FK_Orders_Customers"
* m_OrdersGrid.DataSource = m_ChildOrdersBindingSource

Robin S.

Flomo Togba Kwele

Thanks for the response Robin.

I set all the binding properties in the Property window. When I select
the child bindingsource and set its datasource to the bindingsource of
its parents, no items are available to select in the DataMember

So I set it up as you did in the Load event. It won't even load the
form because it cannot find one of the properties associated with the
Child bindingsource.

PersonBindingSource.DataSource = ClientBindingSource
PersonBindingSource.DataMember = "FK_Client_Person"

System.ArgumentException was unhandled
Message="Cannot bind to the property or column FirmName on the
Parameter name: dataMember"

Can you think of any reason that it cannot see the DataMember?



This message seems to indicate that there are fields involved in the FK
that are not in the datatable. Is that true?

According to your original post, the Person is the parent and the Client is
the child. The only way to move through the records together if you can't
change that is by using the Person as the parent instead of the Client.

I don't understand why you can't change the relation, unless that's how it
is defined in your original data source (database).

Robin S.

Flomo Togba Kwele

Thanks for the push, Robin. I figured out how to change the
relationships. I wasn't setting the columns properly.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question