4
Answers

Getting your last saved record in database

Ask a question
Hi guys. When I insert a new record to my database, I need to grab the ID (identity/auto increment field) of that record RIGHT AWAY. What I have done in the past, is to run a query SELECT MAX(ID) FROM right after I inserted the new record, but this can't be a fool-proof way of doing it. What if someone else inserts a new record before I run my SELECT MAX query? So, my question is: does anyone know of a better way? Is there any built-in functionality for this in ADO.NET? Thanks!
Answers (4)