Last post May 26, 2019 02:27 PM by PatriceSc
May 26, 2019 05:04 AM|hkbeer|LINK
I have a need for a boss to create a database entry (So ID is created) but at the same time save this ID and his keyed in field values into the database.
Of course this is ok when all are saved to single table but this also means this is not normalized.
What I wish is when he typed all data and push go button,
First SetID and his create time and ID is saved to Set Table A, and then his entered values in other field is saved to DataTableB with SetID from Table A.
I am able to create new row in Table A, and I am able to save other values to DataTableB, but I am not able to save the SetID from TableA into the TableB in this same entry when adding data row to TableB.
Please help. How would you solve this problem ?
May 26, 2019 02:27 PM|PatriceSc|LINK
If using ADO.NET you can use https://www.aspsnippets.com/Articles/Get-ID-of-last-inserted-record-using-ADONet-and-SCOPEIDENTITY-in-ASPNet-MVC.aspx to
query for the newly created id.
If using Entity Framework you can save multiple related rows and EF handles all this for you behind the scene (ie it will insert rows in the correct order and will move newly generated values to "child" rows as needed, all this into a single transaction).
I would suggest to study EF if not done already.