Master-Detail Relationship

G

Good

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
 
M

mikeinthemud

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)
 

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

Top