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

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

P: n/a
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
Oct 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

On Thu, 05 Oct 2006 00:49:25 -0700, Hexman <He****@binary.comwrote:
>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
Oct 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.