One-to-One relationship RRS feed

  • Question

  • I have a parent table containing Instruments with InstID as the primary key/Identity field. Increment and seed are set to 1.

    There are 27 child tables with Instrument Details which have their own ID related back to Instruments one-to-one on InstID. These 27 child tables have different fields for different Instrument types.

    I want 27 forms to be able to enter in each Instrument's information according to the different fields in the Instrument Details table. I don't want to use DataGrid View for this purpose. I'm using text boxes and combo boxes.

    I think I'm on the right track, but I'm stuck at adding records. My data sources for parent and child table are correct. I can successfully display records and update them on the same form using text boxes and combo boxes. as long as the one -to-one relationship already exists. However, I can't add a new Instrument and associated Detail record with matching ID's.

    I've tried the GetChanges method using this example http://msdn2.microsoft.com/en-us/library/4esb49b4(VS.80).aspx

    I've tried the Select method as mentioned by David Sceppa in his post here: https://forums.microsoft.com/msdn/showpost.aspx?postid=184395&siteid=1

    Neither of these has worked when trying to add new records. When displaying ID for both InstrumentsTable and DetailsTable, the ID for DetailsTable never updates automatically to match InstrumentsTable.ID.

    My FK Constraint is set to "Relation and FK Contraint", Cascade Updating, Cascade Deletion, and No Accept/Reject rules. I've updated my childTableAdapters. So I'm wondering if I'm missing something.

    Please help! Thx.


    Monday, January 15, 2007 10:23 AM


All replies

  • Just a thought. Try setting your FK Constraint to Relation Only and see if it allows you to insert records.
    Monday, January 15, 2007 10:31 AM
  • Thanks for the suggestion, but it still isn't updating the child table. After submitting the update with the select command, I see that records get added to the parent table, but it doesn't fetch the auto-increment value of the new record and plug it into the child table whose binding source is on the form I'm using.

    Something worth mentioning is that I'm using parenttableBindingSource.AddNew command to try to insert new records, and it always adds two records instead of one. Not sure why its doing this.

    Thanks for the quick response.


    Monday, January 15, 2007 10:53 AM
  • This question has been answered in the following post:


    My problem had to do with my relation set-up in my dataset.

    Thanks Valentine!!!
    Wednesday, January 17, 2007 8:29 PM