Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / April 2006

Tip: Looking for answers? Try searching our database.

ForeignKeyConstraint Problem (Creating Child Record)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Aziz - 11 Apr 2006 11:40 GMT
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.
Aziz - 11 Apr 2006 13:16 GMT
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.... :)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.