Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net SQL Get Primary Key/ID number on Insert

Hi

What VB.net code would I use to insert a record and then get the primary key or ID value
of the newly inserted record?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok.. too many solutions. The idea here is to append a SELECT statement that gives the last used identity value, to your regular INSERT query, and then execute the command using ExecuteScalar() instead of ExecuteNonQuery() method. ExecuteScalar will give you a single column single row result.
Avatar of Murray Brown

ASKER

Thanks very much