Navigating parent-child relation to update the child records --- How???

H

Hexman

Hello All,

What I'm trying to do is update a child record using a parent-child relation. I want to find out if it is faster than than doing multiple selects.
Anyways, I've created a dataset (ds), have 2 datatables (dtRC and dtST). Created the parent-child relationship with multiple columns and added the
relation to the dataset.

Now what I want is to move through each of the dtRC (parent) records, get all related dtST (child) records and update the child records with data from
the parent. In the code below RCCount is the number of parent records that are in dtRC.

After running the code it goes thru each parent and EVERY child for each parent. Have to limit the children for each parent.

How do I know how many children the parent has? I know I have to put the Update and AcceptChanges in after this update.

What am I missing in this puzzle?

I know there is an easy way to do this. I just don't know it yet. Got a lot of Googling to do, but can you help me on this one now?

Thanks,

Hexman

==================================================
Private Sub Process1()
Dim Idx As Integer
Dim Idx2 As Integer

' Define the relationship between the tables.
Dim parentColumn() As DataColumn
parentColumn = New DataColumn() {dtRC.Columns("RCDate"), dtRC.Columns("RCItem"), dtRC.Columns("RCMfgNum")}
Dim childColumn() As DataColumn
childColumn = New DataColumn() {dtST.Columns("STDate"), dtST.Columns("STItem"), dtST.Columns("STMfgNum")}
Dim dRelRCST As DataRelation
dRelRCST = New DataRelation("RC-ST", parentColumn, childColumn)
' Add the relation to the DataSet
ds.Relations.Add(dRelRCST)

For Idx = 0 To RCCount - 1
For Idx2 = 0 To ????????
dtST.Rows(Idx2).Item("STPriVend") = dtRC.Rows(Idx).Item("RCPriVend")
Next
Next
End Sub
 
H

Hexman

I think I've found it!!!

Dim drRC As DataRow
Dim drST As DataRow
For Each drRC In dtRC.Rows
For Each drST In drRC.GetChildRows(dRelRCST)
drST.Item("STPriVend") = drRC.Item("RCPriVend")
Next
Next

While I'm here can anyone enhance my code below or the code above?

Hexman
 

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