468,243 Members | 2,037 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,243 developers. It's quick & easy.

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

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
1 2578
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.

Similar topics

5 posts views Thread by skip | last post: by
3 posts views Thread by Adrian | last post: by
3 posts views Thread by Paul Neave | last post: by
4 posts views Thread by jenyb via DotNetMonster.com | last post: by
3 posts views Thread by BobAchgill | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.