tmace74
asked on
Merging two datatables in a single dataset
Hello Experts,
I am new to VB.NET and am trying to merge two datasets into one by looping through the first using a for Each loop and the second table using a For loop then I use an if, which doesn't currently work, to compare the UserID in each table, in the Address table the UserID is not always unique so I can't use a parent child relation to do this join. I unfortunately cannot do this join in the database so I have to do a merge in .net. Any help on how best merge these two tables would be greatly appreciated.
For Each drSuppData In dsData.Tables("Addresses") .Rows
For i = 0 To dsData.Tables("Users").Row s.Count - 1
TmpUserID = CType(dsData.Tables("Users ").Rows(i) .Item("Use rID"), String)
If TmpUserID = (drSuppData.Item("UserID") Then
dsData.Tables("Users").Row s(i).Item( "Address") = drSuppData.Item("Address")
End If
Next i
Next
Thanks,
Tim
I am new to VB.NET and am trying to merge two datasets into one by looping through the first using a for Each loop and the second table using a For loop then I use an if, which doesn't currently work, to compare the UserID in each table, in the Address table the UserID is not always unique so I can't use a parent child relation to do this join. I unfortunately cannot do this join in the database so I have to do a merge in .net. Any help on how best merge these two tables would be greatly appreciated.
For Each drSuppData In dsData.Tables("Addresses")
For i = 0 To dsData.Tables("Users").Row
TmpUserID = CType(dsData.Tables("Users
If TmpUserID = (drSuppData.Item("UserID")
dsData.Tables("Users").Row
End If
Next i
Next
Thanks,
Tim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am using the dataset in a Crystal Reports file to generate a report.
It does not matter how you created your dataset. The examplpe shows how to merge 2 datasets and enter key into them to eliminate duplicates
Hi
Use the Merge() Method.
Use the Merge() Method.
You might consider creating a hashtable lookup first, with the userID as a key and the address as value to have a quick lookup for your suppliers