473,324 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Updating Master – Detail Records

Echooff3
My application utilizes a dataset with a couple of One to Many relations. If the user adds a new record and adds information to the master part of the form and adds information to the detail part of the form then clicks save. The master record gets saved and the detail throws a “INSERT statement conflicted with the FOREIGN KEY constraint … The conflict occurred in “MasterTable”, “MasterTableID”.

My save routine goes like this:
Expand|Select|Wrap|Line Numbers
  1. Me.Validate () ‘ Validates the form
  2. MasterBindingSource.EndEdit
  3. MasterTableTableAdapter.Update(DataSet.MasterTable)
  4. DetailBindingsource.EndEdit
  5. DetailTableAdapter.Update(DataSet.DetailTable)
  6.  
I checked the row data for the Master Table and it’s identity updated from 0 to the next ID. When I check the foreign column on the Detail table it’s still 0. So when the update hits the constraint is invalid and throws the error. Blaming the Master Table even though it has the updated ID. Is there something wrong in my EndEdit / Update Sequence that the foreign key on the detail table is not updating???
Dec 5 '07 #1
1 2319
I think I have answered my issue. I removed the default FILL statement (in the form load event) that gets autogenerated in the IDE. My application pulls over 20K records so that would create a huge lag in performance. So when I called AddNew from the Master BindingSource it left the ID as 0. And sending 0 as the foreign key values to all the detail tables. So I created a query in my datatables to pull the Last record and load up the dataset intially. I don't understand why this works? Why is it necessary to fill the dataset before adding a new record?

When I update without calling inital Fill it updates the Master record fine but the changes don't propigate through the subtables. But if I call the fill first it does propigate???

Can some one explain this to me?
Dec 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ozgur YASAR | last post by:
Hi, i need to be able to active; on the first page a process is started with a (master) record insert and it will open next page on the next page a datagrid will be used to insert update...
2
by: HS1 | last post by:
Hello all I followed the example in Visual Studio.net to create a master and detail relationship as following: two tables: Customers and Orders two DataGrid: GridOrders and GridDetails...
9
by: Mr Newbie | last post by:
HI People, Thanks to all who helped me earlier on the subject of @@IDentity. However, I seem to have hit another snagette! My DataSet contains two tables from the SQL Server. lets say Master...
0
by: Sam | last post by:
Folks, Attached I am sending 2 URL's from MSFT ASP.net Quick Start Tutorial Web Site. 1) Run it URL: http://www.asp.net/QuickStart/aspnet/samples/data/GridViewMasterDetailsInsertPage_vb.aspx 2)...
1
by: Sam | last post by:
Attached I am sending 2 URL's from MSFT ASP.net Quick Start Tutorial Web Site. 1) Run it URL: http://www.asp.net/QuickStart/aspnet/samples/data/GridViewMasterDetai... 2) View Source URL:...
0
by: Sam | last post by:
Sorry to post the same post multiple times but the URL Addresses were not Correct in Earlier Posts. Here are the correct URL's: 1) Run It URL is here: ...
1
by: Parasyke | last post by:
I have a dilemma. I have 20 branch offices that need to be able to upload their unique copy of all their backend tables to a master database at a corporate office. I really need only a copy of...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
2
by: John | last post by:
Hi I am trying to create a master/detail form. I have my master and details tables dragged onto the dataset. I have also dragged the fields from master table on the form which has created the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.