none
Add child record before adding parent record RRS feed

  • Question

  • I have 2 table:

    tblParent>PK AutoIncrament = RunID

    tblChild>PK AutoIncrament = ChildID>FK Integer = RunID

    I am receiving data from a serial connection.  The data for the master record is sent every 5 seconds.  After that a series of child records may arrive.  In the case where the connection misses the master record, I want to be able to still store those received records in the DataSet datatable, but not write them to the database yet, because I don't have the FK.

    Then when I finally receive the master record, I want to create a record in the DataSet table, then save it to the database to get the PK.  The insert that PK value into the FK in the records of tblChild that have not been saved to the database yet.  Then after the FK is inserted into those records, then I can save them to the database.

    How would I do this?

    Monday, February 13, 2012 9:56 PM

Answers

  • Hi,

    if I understand correctly,

    you sometimes have childrecords, without having received the parent record yet.

    In that case, I would create a dummy parent record, add the childrecords with the dummy as parent,

    and when you receive the parent data, update the dummy with the reiceved parent data.


    Regards, Nico

    • Marked as answer by viacuda77 Wednesday, February 15, 2012 8:51 PM
    Tuesday, February 14, 2012 1:50 PM

All replies

  • Hi viacuda77,

    According to your description, you receiving data from one database then save them into another database, right? I think you can use "Hierarchical Update": http://msdn.microsoft.com/en-us/library/bb384432.aspx  put the records in to dataset(set relations in dataset), then call UpdateAll().

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 14, 2012 7:00 AM
    Moderator
  • Hi,

    if I understand correctly,

    you sometimes have childrecords, without having received the parent record yet.

    In that case, I would create a dummy parent record, add the childrecords with the dummy as parent,

    and when you receive the parent data, update the dummy with the reiceved parent data.


    Regards, Nico

    • Marked as answer by viacuda77 Wednesday, February 15, 2012 8:51 PM
    Tuesday, February 14, 2012 1:50 PM