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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Databases: Get ID of new record after INSERT 2

Status
Not open for further replies.

4waystop

Programmer
Aug 30, 2004
19
GB
Hi

I've been relentlessly querying google about this and got nowhere, all I can find is how to do it in VB Script or using LiveWire.

What I want to know is once I've inserted a new record to the database (in this case MS SQL Server), how do I find out the Autogenerated indexing number for that record?

Currently I have:

var adoConnection = Server.CreateObject("ADODB.Connection");
adoConnection.Open("Data Source=***;Database=
***;User Id=***;Password='***'");

var perSQL = "INSERT INTO ... VALUES(...)";
RS = adoConnection.Execute(perSQL);

At this point I need to get the ID of the record inserted and then use it in a second insert procedure.

All Help Much Appreciated!!

Thanks
 
All you have to do is SELECT @@Identity
If you google that you should find tons of stuff.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top