ADO.NET method to capture newly inserted row's key.
Posted on 2003-11-07
I have two tables in SQLServer.
I insert a new row into table1, which creates a new ID as an identity default primary key.
I need to get that key value to update a second table as a foreign key relationship to the first table.
I could use a command object to insert the table1.row and another to return the most recently added id-key.
I could use a command object to run a stored procedure that returns as an output parameter the id-key.
I could ask the experts what the proper way to accomplish this is. . .
I prefer to learn the best way to do this using ADO.NET.