By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,285 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,285 IT Pros & Developers. It's quick & easy.

Master-Detail Relationship

P: n/a
Hi all

I have created a master-detail relationship dataset under VS2005. However,
when I update the tables, it seems the foreign key information couldn't be
passed from the master table, therefore, the update is failed. Do you know
how to solve this problem?

Cheers
Good
Feb 23 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
While updating related tables in a dataset, it is important to update in the proper sequence to reduce the chance of violating the relation between tables. To prevent data integrity errors update the data source in the following sequence:

Child table: delete records.
Parent table: insert, update, and delete records.
Child table: insert and update records.

Private Sub UpdateDB()
Dim DeletedChildRecords As DataTable = _
DS.Orders.GetChanges(DataRowState.Deleted)
Dim NewChildRecords As DataTable = _
DS.Orders.GetChanges(DataRowState.Added)
Dim ModifiedChildRecords As DataTable = _
DS.Orders.GetChanges(DataRowState.Modified)
Try
If Not DeletedChildRecords Is Nothing Then
DAOrders.Update(DeletedChildRecords)
DeletedChildRecords.Dispose()
End If
DACustomer.Update(DS, "Customer")
If Not NewChildRecords Is Nothing Then
DAOrders.Update(NewChildRecords)
NewChildRecords.Dispose()
End If
If Not ModifiedChildRecords Is Nothing Then
DAOrders.Update(ModifiedChildRecords)
ModifiedChildRecords.Dispose()
End If
DS.AcceptChanges()
Catch ex As Exception
' Update error, resolve and try again
End Try
End Sub

As an alternative download IdeaBlade’s DevForce Express and use that for ORM (I don’t work for them – but use it extensively)

Apr 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.