Trying to use SELECT SCOPE_IDENTITY() ID and just simply write back the value:
Here is my full code:
<!DOCTYPE html><!--#include virtual="/Connections/connTickets.asp"--> <html><body><head><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"><script src="http://code.jquery.com/jquery-1.11.2.min.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script><title>Department of Psychiatry Information Systems</title><meta name = "viewport" content = "width = device-width"></head><button type="button" onClick="history.go(-1);">Back</button><br><br><% set rs=Server.CreateObject("ADODB.recordset") snameFirst = Request.Form("nameFirst") snameFirst = Replace (snameFirst, "'", "''") snameLast = Request.Form("nameLast") snameLast = Replace (snameLast, "'", "''") sDescription = Request.Form("Description") sDescription = Replace (sDescription, "'", "''") sql="INSERT INTO Tickets (nameFirst,nameLast,Division, Building, Floor, Room, Phone, Description)" sql=sql & " VALUES " sql=sql & "('" & snameFirst & "'," sql=sql & "'" & snameLast & "'," sql=sql & "'" & Request.Form("Division") & "'," sql=sql & "'" & Request.Form("Building") & "'," sql=sql & "'" & Request.Form("Floor") & "'," sql=sql & "'" & Request.Form("Room") & "'," sql=sql & "'" & Request.Form("Phone") & "'," sql=sql & "'" & sDescription & "');SELECT SCOPE_IDENTITY() ID;" conn.Execute sql,recaffected if err<>0 then response.write("No update permissions!") else response.write rs("ID") response.write("<h3>" & recaffected & " Ticket Added</h3>") end if Response.AddHeader "REFRESH", "1;URL=AddTicket.asp" conn.close%></body></html>
Everything works except when I added the: response.write rs("ID")
My Primary key of this table is called TicketNumber and I simply want to be able to reference the TicketNumber that was just inserted later on down this page. I thought: SCOPE_IDENTITY() is what I wanted, right?
I get a 500 error when the Response.write is in.
What am I doing wrong?
Thanks,
Scott