Avatar of Murray Brown
Murray Brown
Flag 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?
Visual Basic.NETMicrosoft SQL Server

Avatar of undefined
Last Comment
Murray Brown

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Brijesh Gandhi

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Harish Varghese

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.
Murray Brown

ASKER
Thanks very much
Your help has saved me hundreds of hours of internet surfing.
fblack61