PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
ForeignKeyConstraint Problem (Creating Child Record)
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
ForeignKeyConstraint Problem (Creating Child Record)
![]() |
ForeignKeyConstraint Problem (Creating Child Record) |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hello, my main VB .NET 2003 + Access program wasn't working so I
created two small sample applications to test why I get the following error: ForeignKeyConstraint ProductOrder_Product requires the child key values (AAA-BBB-1) to exist in the parent table. My first application works and creates a child record fine. My second application is almost exactly the same but it doesn't work (I get the above error, even though I KNOW for a fact that the value does exist in the parent table). Can anyone help me if I send them the source code? The code is very small (only around 10 lines). No matter what I try it seems I'm banging my head against a harder than brick wall. Here's the code though: Private Sub btnPlaceOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaceOrder.Click Dim drOrder As DataRow = Turboset.Orders.NewRow() drOrder.Item("ShippingName") = "Gah" drOrder.Item("CustomerID") = 7 Turboset.Orders.Rows.Add(drOrder) daOrders.Update(Turboset, "Orders") 'Gets OrderID of last added new Order row Dim lastOrderID As Integer lastOrderID = CInt(Turboset.Orders.Rows(Turboset.Orders.Rows.Count - 1).Item("OrderID")) Dim drOrderProduct As DataRow = Turboset.OrderProduct.NewRow drOrderProduct.Item("OrderID") = lastOrderID drOrderProduct.Item("ProductID") = "1" Turboset.OrderProduct.Rows.Add(drOrderProduct) daOrderProduct.Update(Turboset, "OrderProduct") End Sub If someone can help me I can send them the zip file (it's only around 350kB) which includes the databases too. Or you can get it here: http://ultrashare.net/hosting/fl/ce6e2268b8/ http://rapidshare.de/files/17722654/help.zip.html Thanks. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
I finally worked it out. It turns out I need to fill ALL the
dataadapters for all the tables that are used (even if they're not written to) and fill them in the right order (parent tables first). 4 books on my desk and not one makes this clear. You'd think they'd print out this stuff in size 30 font on a double page spread on it's own. The amount of headache it's caused me... Jesus, it's ben a long struggle.... ![]() |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 


