All Forums >> [Scripting] >> ASP >> SQL Insert Into return the Autonumber Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
The table EmailChanges has a field called "ChangeNumber" which is an AutoNumber field. This number is allocated by the database and placed into the new row.
How can my ASP script add the new row in a way that the script learns what ChangeNumber has been allocated?
Posts: 8
Score: 0
Joined: 4/1/2005
From: USA
Status: offline
I think I found the answer. I'm not sure if I have to use Transactions to prevent anyone else from modifying that table between my two statements, but it seems safe. Here's the code without error checking:
my_Conn.BeginTrans sql = "INSERT INTO EmailChanges (Oldmail, Newmail) VALUES (" sql = sql & strOldmail & ", " & strNewmail & ")" my_Conn.Execute sql Set rs = myConn.Execute("Select @@Identity as x") my_conn.CommitTrans Response.Write "<p>New ID value=" & rs.Fields("x") & "</p>"
I think I found the answer. I'm not sure if I have to use Transactions to prevent anyone else from modifying that table between my two statements, but it seems safe. Here's the code without error checking:
my_Conn.BeginTrans sql = "INSERT INTO EmailChanges (Oldmail, Newmail) VALUES ('" sql = sql & strOldmail & "', '" & strNewmail & "')" my_Conn.Execute sql Set rs = myConn.Execute("Select @@Identity as x") my_conn.CommitTrans Response.Write "<p>New ID value=" & rs.Fields("x") & "</p>"