"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:OS**************@tk2msftngp13.phx.gbl...
In my Form, there is Invoice Master to - InvoiceDetail (one-to-may
relationship)
I use bmMaster.removeat(bmMaster.position) to remove the Master record.
However, I don't know how to remove the Detail records ????
I got relationkey between that two tables.
Dim constraint_tinvno As New ForeignKeyConstraint("fk_tinvno",
dtTvHeader.Columns("tinvno"), dtTvDetail.Columns("tinvno"))
dtTvDetail.Constraints.Add(constraint_tinvno)
dsTvHeader.Relations.Add("fk_tinvno",
dtTvHeader.Columns("tinvno"), dtTvDetail.Columns("tinvno"), False)
Here's an example code snippet that illustrates what you need to do:
' Creating the DataRelation between Customers and Orders Tables
Dim pCol1 As DataColumn
Dim cCol1 As DataColumn
Dim myFKC1 As ForeignKeyConstraint
pCol1 = dsCustomers.Tables("Customers"*).Columns("Customer ID")
cCol1 = dsCustomers.Tables("Orders").C*olumns("CustomerID" )
Dim CustomersOrders As New DataRelation("CustomersOrders"*, pCol1,
cCol1)
dsCustomers.Relations.Add(Cust*omersOrders)
myFKC1 = New ForeignKeyConstraint("Customer*sOrders1", pCol1, cCol1)
'************************************************* *****************
' By setting the DeleteRule to Rule.Cascade, child table records related to
the parent table
' record you delete will be deleted automatically
myFKC1.DeleteRule = Rule.Cascade
myFKC1.UpdateRule = Rule.Cascade
dsCustomers.Tables("Orders").*Constraints.Add(myFK C1)
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.