Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb.net get last insert id from sql server 2008

Status
Not open for further replies.

wjaram

Programmer
Apr 21, 2009
2
US
I'm executing a query in vb.net inserting a row into an sql server 2008 table. The table has a unique id column that auto increments on each insert. How do i get the value of the id created on the last insert. What I need is equivalent to mysql_insert_id(); in php and mysql, but I need it for vb.net and sql 2008. I'm not using a stored procedure. It an insert query directly in vb.net.

Any help would be much appreciated. I've scoured the world wide web but I haven't been able to find the answer.
 
I'm not a SQL server guru so I could be wrong on this, but as far as I remember an auto ID doesn't exist until the table has been updated and saved. The only way to get the id is to requery the table or keep track of what the ID should be.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top