Suppose I have a Table:
FieldWorker{ ID, Name, WorkingArea}
And, ID
is an auto-incremented field.
Now, suppose, I am using the following code to insert records:
sqlComm.ExecuteNonQuery("INSERT INTO [FieldWorker]
([Name]
,[WorkingArea])
VALUES
(@Name
,@WorkingArea)");
What technique can I use to retrieve the maximum value of auto-incremented ID
field that has been generated upon the insertion of the latest record?
Both the insertion-code and the retrieval of ID
-value must be done under a single SqlTransaction
object.
Why must I use ExecuteScalar()
?