Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Retrieve an Identity Value from a Newly Inserted Record from SQL Server


Message #1 by "mike.carlton@b... on Tue, 9 Jul 2002 13:20:46
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

------------------------------------------------
Message #2 by "Chirag Shah" <chiragiit@y...> on Tue, 9 Jul 2002 14:18:01
Use: @@identity
for more help: search in previous post on this forum. 

  Return to Index