PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET ForeignKeyConstraint Problem (Creating Child Record)

Reply

ForeignKeyConstraint Problem (Creating Child Record)

 
Thread Tools Rate Thread
Old 11-04-2006, 11:40 AM   #1
Aziz
Guest
 
Posts: n/a
Default ForeignKeyConstraint Problem (Creating Child Record)


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.

  Reply With Quote
Old 11-04-2006, 01:16 PM   #2
Aziz
Guest
 
Posts: n/a
Default Re: ForeignKeyConstraint Problem (Creating Child Record)

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

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off