How to get the last inserted ID from the table ?



There are two ways to get the ID of the last inserted record.
@Identity()
@Scope_Identity()

EX:
String  Squlquery = “insert into tablename(categoryname) values (@categoryname);”  + “Select  Scope_Identity()”;

So use ExecuteScalar to get the ID of the last inserted Record.

Int getLastID = (int) cmd.ExecuteScalar();


0 comments: