asp_databases thread: Retrieve an Identity Value from a Newly Inserted Record from SQL Server
Can someone please help!
I am performing a simple record addition using data supplied in a form.
Once the recordset has been updated using the RecordsetName.Update method
I want to obtain the new identity which SQL 2000 has produced.
The new identity value needs to be stored in a variable or other format
to be used in a querystring.
Thanks!
Mike
P.S. code below
------------------------------------------------
Dim RsProduct, IntProductID
Set RsProduct = Server.CreateObject("ADODB.Recordset")
RsProduct.Open "Products", DcHealth, adOpenDynamic,
adLockPessimistic
'We want to check the querystring to see if the
If Request.QueryString <> "true" Then
'We want to update a product
RsProduct.AddNew
Else
RsProduct.MoveFirst
RsProduct.find "ProductID = '" & Request.Form
("ProductID") & "'"
End If
'Process the form fields
RsProduct.Fields("Name") = Request.Form("Name")
RsProduct.Fields("Details") = Request.Form("Details")
RsProduct.Fields("Description") = Request.Form
("Description")
RsProduct.Fields("Price") = Request.Form("Price")
RsProduct.Fields("Cost") = Request.Form("Cost")
RsProduct.Fields("SupplierID") = Request.Form
("SupplierID")
RsProduct.Fields("ManuID") = Request.Form("ManuID")
RsProduct.Fields("DepartmentID") = Request.Form
("DepartmentID")
If Request.QueryString <> "true" Then
'Add the user, if we are updating we do not want
to change this data
RsProduct.Fields("UserCreated") = Session
("usrname")
Else
End IF
RsProduct.Update
IntProductID = RsProduct("ProductID")
RsProduct.Close
Set RsProduct = Nothing
DcHealth.Close
Set DcHealth = Nothing
------------------------------------------------