C
Christian Findt
Hi there,
I'm trying to load two tables in one dataset and connecting them with a
relation. Unfortunately, the result isn't as expected. Instead to load both
tables correctly, the field "KdNr" in the child table stays empty. In the
end, the function "GetChildRows" cannot find anything.
Well, the question is why? Is it my fault which would be my guess or is it a
know bug in the system. I was working close on examples I found on numerous
sites but I'm not sure how I transformed them. I would appreciate any kind
of help on this one.
I'm working with a local Access database.
These are my Select-Strings: (shortend)
----------------------------------------------------------------------------
myOrdersSel = "SELECT Orders.Nr, Orders.ODate, Orders.InDate, Orders.KdNr,
[...], Orders.MdValDat, Customers.KdNr," & _
" Customers.KdName, Customers.KdTyp FROM Orders
INNER JOIN Customers ON Orders.KdNr = Customers.KdNr;"
myCustSel = "SELECT Customers.KdNr, Customers.KdAnrede, Customers.KdTitel,
Customers.KdName, Customers.KdVorn," & _
[...] "Customers.KdTyp, Customers.KdBriefanr FROM
Customers;"
----------------------------------------------------------------------------
The Code:
----------------------------------------------------------------------------
daC = New OleDb.OleDbDataAdapter(myCustSel, conn)
daO = New OleDb.OleDbDataAdapter(myOrdersSel, conn)
conn.Open()
If f = False Then
daO.Fill(dsO, "Orders")
Else
daC.Fill(dsO, "Customers")
daO.Fill(dsO, "Orders")
dr = New DataRelation("RelCO", dsO.Tables("Customers").Columns("KdNr"),
dsO.Tables("Orders").Columns("KdNr"))
dsO.Relations.Add(dr)
Dim rC, rO As DataRow
For Each rC In dsO.Tables("Customers").Rows
Console.WriteLine(rC("KdNr") & " - " & rC("KdName"))
For Each rO In rC.GetChildRows("RelCO")
Console.WriteLine(vbTab & rO("Nr") & " - " & rO("KdNr"))
'No result because field Orders.KdNr is empty.
Next
Next
End If
conn.Close()
----------------------------------------------------------------------------
The result:
----------------------------------------------------------------------------
50075 - Kram
13469 - Albin
55408 - Freytag *without child info!
----------------------------------------------------------------------------
checking the field directly:
Console.WriteLine(rO("Nr") & " - " & rO("KdNr")):
----------------------------------------------------------------------------
3288 -
3300 -
3284 - *KdNr is empty
I'm trying to load two tables in one dataset and connecting them with a
relation. Unfortunately, the result isn't as expected. Instead to load both
tables correctly, the field "KdNr" in the child table stays empty. In the
end, the function "GetChildRows" cannot find anything.
Well, the question is why? Is it my fault which would be my guess or is it a
know bug in the system. I was working close on examples I found on numerous
sites but I'm not sure how I transformed them. I would appreciate any kind
of help on this one.
I'm working with a local Access database.
These are my Select-Strings: (shortend)
----------------------------------------------------------------------------
myOrdersSel = "SELECT Orders.Nr, Orders.ODate, Orders.InDate, Orders.KdNr,
[...], Orders.MdValDat, Customers.KdNr," & _
" Customers.KdName, Customers.KdTyp FROM Orders
INNER JOIN Customers ON Orders.KdNr = Customers.KdNr;"
myCustSel = "SELECT Customers.KdNr, Customers.KdAnrede, Customers.KdTitel,
Customers.KdName, Customers.KdVorn," & _
[...] "Customers.KdTyp, Customers.KdBriefanr FROM
Customers;"
----------------------------------------------------------------------------
The Code:
----------------------------------------------------------------------------
daC = New OleDb.OleDbDataAdapter(myCustSel, conn)
daO = New OleDb.OleDbDataAdapter(myOrdersSel, conn)
conn.Open()
If f = False Then
daO.Fill(dsO, "Orders")
Else
daC.Fill(dsO, "Customers")
daO.Fill(dsO, "Orders")
dr = New DataRelation("RelCO", dsO.Tables("Customers").Columns("KdNr"),
dsO.Tables("Orders").Columns("KdNr"))
dsO.Relations.Add(dr)
Dim rC, rO As DataRow
For Each rC In dsO.Tables("Customers").Rows
Console.WriteLine(rC("KdNr") & " - " & rC("KdName"))
For Each rO In rC.GetChildRows("RelCO")
Console.WriteLine(vbTab & rO("Nr") & " - " & rO("KdNr"))
'No result because field Orders.KdNr is empty.
Next
Next
End If
conn.Close()
----------------------------------------------------------------------------
The result:
----------------------------------------------------------------------------
50075 - Kram
13469 - Albin
55408 - Freytag *without child info!
----------------------------------------------------------------------------
checking the field directly:
Console.WriteLine(rO("Nr") & " - " & rO("KdNr")):
----------------------------------------------------------------------------
3288 -
3300 -
3284 - *KdNr is empty