last insert id of insert method

FuZion

Well-known member
Joined
Jan 28, 2007
Messages
47
Programming Experience
Beginner
I have an insert method, of which I need the id that was automatically added via an identity. How do I get this?

Thanks!
 
Run an ExecuteScalar command, with "; SELECT SCOPE_IDENTITY()" after your Insert query.
 
Ok so can I do that within the INSERT query method itself? Because right now I call tableAdapter.customInsertMethod(xxx,xxx,xxx,xxx) and I believe it returns the number of rows affected, because it returns 1 every time. But the VS wizard adds a select statement that I rewrote to select the last ID. The only problem is I don't know how to access it, so how do I get at the value returned from the select statement in my method?
 
Back
Top