Help requested with updating child's foreign key value in datarelation

  • Thread starter Thread starter LBC
  • Start date Start date
L

LBC

I have a DataSet that contains 3 DataTables for which I have created a
DataRelation. The tables are: Department - DeptID is PK,
Subdepartment - SubdeptID is PK and DeptID is FK, and Room - RoomID is
PK and SubdeptID is FK. All tables have additional fields such as
name, description, etc. Sample data is as follows:

Depts SubDepts Rooms
DeptID SubdeptID DeptID RoomID SubDeptID
01 001 01 A 001
02 002 01 B 002
C 002

The Dataset is bound to a datagrid that is displaying as follows:

Dept 01
Subdept 001
Room A
Subdept 002
Room B
Room C
Dept 02
..
..
..

My problem appears when I try to move a room from one subdepartment to
another. I change the value of the Room's SubDeptID to the desired
SubDeptID (i.e., move Room B from Subdept 002 to Subdept 001) and when
I update the DataAdapter, everything appears to have worked perfectly.
The datagrid reorders itself properly so that Room B is now under Room
A. Also any additional changes to fields such as name and description
refresh in the datagrid too. But if I rerun the application or refresh
the datagrid, the changes to the SubDept ID did not take (although the
changes to the other fields did). If my changes don't touch the
SubdeptID, they are all accepted fine. I have EnforceConstraints =
True in my DataSet. I have tried putting an AcceptChanges on the
DataSet right after making my changes and before the
DataAdapter.Update. I have an EndEdit on the DataRow. None of these
things seem to help. Any suggestions?
 
LBC,

Something funny is going on.

Make the change that you think "takes" in the database.
Shut down the applicaton
Test the database
Restart the application and test

I suspsect a programming error is resulting in teh database not actually
being updated. However the above will disprove that theory (debugging is
about disproving, not proving). If the above works correctly, then it sounds
like a weird caching problem.

Also, I assume you are using a WIndows.Forms DataGrid, since the Web one is
readonly. Please specify the DataGrid type though.
 
Back
Top