|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Getting unique id for a newly added record (SQL)
Hi All,
I am converting an ASP web application that originally used MS Access to MS SQL. The database is fairly complex and I had no problem importing the access DB to MS SQL. In one section, the user adds a new record to the DB. There are several pages of form information that is part of a new record. With Access, I was able to use the following to grab the counter (unique id) from the newly added record (so send so the subsequent pages: rs.AddNew [assigning rs fields from form info] rs.Update id = rs("counter") [redirect to next page, if no errors] using SQL, id & rs("counter") never has a value. I assuming I am missing something simple, but cannot figure out what it is. Any help would be great appreciated. thanks, Nick |
|
#2
|
||||
|
||||
|
It's a little tricky the first time around. All DB's have a unique way of doing it. For SQL Server check out this code.
Code:
'--Execute the INSERT statement and the SELECT @@IDENTITY
Set rcs = db.execute("insert into tablename (fields,..) " & _
"values (values,...);" & _
"SELECT @@IDENTITY").nextrecordset
'--Retrieve the @@IDENTITY value
new_identity = rcs(0)
|
|
#3
|
|||
|
|||
|
thanks!
That seemed to do the trick. I doubt i would figured that out on my own
Thanks again, Nick |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Getting unique id for a newly added record (SQL) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|