J
Jason L James
Hi all,
I have created a multi-user app using an MS Access
database in VB.Net. I am using a typed dataset. Each
table has a PK and several have FK relationships to
maintain a one-to-many relationship between parent
and child.
If I add a parent record to the dataset and then a child
record to the dataset the FK of the child is written as
the PK of the parent through my VB code.
However, if another record has been written by another
user the PK of the parent will be changed when the
dataset is updated to the batabase. The FK of the child is not
automatically updated to reflect the change. The new
PK of the parent is not updated in the dataset after
the update command has written the data back to the
database. When this happens the child record is orphaned!!
Does anyone have any suggestions as to how I should
ensure that the referential integrity of the relationship
between the parent and the child is maintained when the
parent dataset is updated and then the child dataset is
updated using the dataAdapter.Update(???) command .
Some code follows below:
Dim newComment As dsProjects.tblCommentRow =
DsProjects1.tblComment.NewRow
newComment.cEvent = sEvent
newComment.cAuthor = sEngineer
newComment.cText = sComment
newComment._cDate = dDate
newComment.csID = StageID
DsProjects1.tblComment.Rows.Add(newComment)
At this point the dataset has a PK value of 4, for example
Dim newAttachment As dsProjects.tblAttachmentRow =
DsProjects1.tblAttachment.NewRow()
newAttachment.acID = newComment.cID
newAttachment.aName = sFileName
newAttachment.aPath = sAttachment
newAttachment.aExt = sExtension
DsProjects1.tblAttachment.Rows.Add(newAttachment)
The FK of the child is written as four in the dataset (the same as
the PK of the parent).
This command will write the data to the database where it might
change the PK to ensure unique rules are not violated.
daComment.Update(DsProjects1.tblComment)
When the child dataset is updated the new PK of the parent will not
be the FK of the child. The record is orphaned.
daAttachment.Update(DsProjects1.tblAttachment)
Any ideas welcomed.
Many thanks,
Jason.
I have created a multi-user app using an MS Access
database in VB.Net. I am using a typed dataset. Each
table has a PK and several have FK relationships to
maintain a one-to-many relationship between parent
and child.
If I add a parent record to the dataset and then a child
record to the dataset the FK of the child is written as
the PK of the parent through my VB code.
However, if another record has been written by another
user the PK of the parent will be changed when the
dataset is updated to the batabase. The FK of the child is not
automatically updated to reflect the change. The new
PK of the parent is not updated in the dataset after
the update command has written the data back to the
database. When this happens the child record is orphaned!!
Does anyone have any suggestions as to how I should
ensure that the referential integrity of the relationship
between the parent and the child is maintained when the
parent dataset is updated and then the child dataset is
updated using the dataAdapter.Update(???) command .
Some code follows below:
Dim newComment As dsProjects.tblCommentRow =
DsProjects1.tblComment.NewRow
newComment.cEvent = sEvent
newComment.cAuthor = sEngineer
newComment.cText = sComment
newComment._cDate = dDate
newComment.csID = StageID
DsProjects1.tblComment.Rows.Add(newComment)
At this point the dataset has a PK value of 4, for example
Dim newAttachment As dsProjects.tblAttachmentRow =
DsProjects1.tblAttachment.NewRow()
newAttachment.acID = newComment.cID
newAttachment.aName = sFileName
newAttachment.aPath = sAttachment
newAttachment.aExt = sExtension
DsProjects1.tblAttachment.Rows.Add(newAttachment)
The FK of the child is written as four in the dataset (the same as
the PK of the parent).
This command will write the data to the database where it might
change the PK to ensure unique rules are not violated.
daComment.Update(DsProjects1.tblComment)
When the child dataset is updated the new PK of the parent will not
be the FK of the child. The record is orphaned.
daAttachment.Update(DsProjects1.tblAttachment)
Any ideas welcomed.
Many thanks,
Jason.