I faced a problem when I try to use the ExecutedScalar() command.
I built a web application, in the web App the user need to fill his details like name, family, hobbies (array), etc.
After the user pushing on the submit button, I collect all the information the user fill and create an object Person and connect to DB and update the personTbl table.
personTbl - I have an ID (identity(1,1)) filed, that means every time I add a new person he gets from SQL Server a new ID.
My question is:
How can I add a new person to DB and at the same time to get is ID from SQL Server?
I use ExecuteNonQuery() to insert the new person, but at the same time, I need to retrieve his ID (using ExecutedScalar()) because I need to use her to do another insert command to a different table.