cjard
Well-known member
- Joined
- Apr 25, 2006
- Messages
- 7,081
- Programming Experience
- 10+
I have two DataTables, related by a DataRelation that forms a relation and an foreign key update/delete cascade.
On a form, some controls are bound to these tables.
When adding a new record, I call
ParentBindingSource.AddNew()
ChildBindingSource.AddNew()
The two binding navigators on the form now correctly show that each source contains a single row. Querying the ParentBindingSource.List.Count and ChildBindingSource.List.Count shows them both to be 1
Immediately that I call ParentBindingSource.EndEdit() (as part of the save routine) the ChildBindingSource list entry disappears and I'm left is a ChildBindingSource.List.Count of 0
If i first call ChildBindingsource.EndEdit, an exception is fired because "ForeignKeyConstraint ParentDT_ChildDTRelation requires the child key values (-1) to exist in the parent table."
When I EndEdit() either, why does the other suddenly lose its related value?
-----------
Here is some more info:
No matter what kind of relation (relation only, fk constraint, both) with whatever combination of update/delete cascades, this behaviour still occurrs
Immediately before Calling EndEdit():
Both Bindingsources have 1 row in their List
Both these rows are RowState "Detached"
Neither of the underlying DataTables have a row
After calling EndEdit on the parent:
The "Detached" row in the child BindingSource's list simply disappears.
The child DataTable has 0 rows.
The parent DataTable has 1 row and its RowState is "Added"
The parent BindingSource has 1 list entry and its RowState is "Added"
------------
It appears I am not the only person to hit this problem..
http://www.eggheadcafe.com/aspnet_answers/NETFrameworkNETWindowsForms/May2006/post26930371.asp
http://www.eggheadcafe.com/aspnet_answers/NETFrameworkNETWindowsForms/May2006/post26930424.asp
But I must ask..
What am I doing that noone else in the world does?
Why isnt everyone complaining that their master/detail relationships dont work?
How do other people get their master/detail forms to work?
On a form, some controls are bound to these tables.
When adding a new record, I call
ParentBindingSource.AddNew()
ChildBindingSource.AddNew()
The two binding navigators on the form now correctly show that each source contains a single row. Querying the ParentBindingSource.List.Count and ChildBindingSource.List.Count shows them both to be 1
Immediately that I call ParentBindingSource.EndEdit() (as part of the save routine) the ChildBindingSource list entry disappears and I'm left is a ChildBindingSource.List.Count of 0
If i first call ChildBindingsource.EndEdit, an exception is fired because "ForeignKeyConstraint ParentDT_ChildDTRelation requires the child key values (-1) to exist in the parent table."
When I EndEdit() either, why does the other suddenly lose its related value?
-----------
Here is some more info:
No matter what kind of relation (relation only, fk constraint, both) with whatever combination of update/delete cascades, this behaviour still occurrs
Immediately before Calling EndEdit():
Both Bindingsources have 1 row in their List
Both these rows are RowState "Detached"
Neither of the underlying DataTables have a row
After calling EndEdit on the parent:
The "Detached" row in the child BindingSource's list simply disappears.
The child DataTable has 0 rows.
The parent DataTable has 1 row and its RowState is "Added"
The parent BindingSource has 1 list entry and its RowState is "Added"
------------
It appears I am not the only person to hit this problem..
http://www.eggheadcafe.com/aspnet_answers/NETFrameworkNETWindowsForms/May2006/post26930371.asp
http://www.eggheadcafe.com/aspnet_answers/NETFrameworkNETWindowsForms/May2006/post26930424.asp
But I must ask..
What am I doing that noone else in the world does?
Why isnt everyone complaining that their master/detail relationships dont work?
How do other people get their master/detail forms to work?
Last edited: