Link to home
Start Free TrialLog in
Avatar of Kevin Smith
Kevin SmithFlag for United States of America

asked on

How do go to asp detail page for record just entered?

I have an insert new employee page in asp.  On submit click, it adds the new record to the database and goes to a "done" page.  How do I get it to immediately go to a detail page for the record that's just been entered?
Avatar of HainKurt
HainKurt
Flag of Canada image

what is detail page?

say it is detail.aspx and accept a querystring with EmpID

then just do this

server.redirect("detail.aspx?EmpID=" & NewEmpID)

or, use session

session("EmpID") = NewEmpID
server.transfer("details.aspx",true)

in detail.aspx use session("EmpID") to show the info... if EmpID is posted to edit page, then you can use

Request("EmpID") on detail.aspx since we transfer the control to detail page (meaning all posted values will be available on that page too) without using session variable...

When you update your database with new employee values, after calling RS.Update use RS.MoveLast to get the ID of the field you just entered, like this::

...
RS.Update
RS.Requery
RS.MoveLast
LastId = RS("emplyee_id")
RS.Close

Response.Redirect "details.asp?id=" LastId
Avatar of Kevin Smith

ASKER

Where would that go?
strSQL = "INSERT INTO Login (FirstName, LastName) " _
& "VALUES ('" & SanitizeSQL(firstname) & "','" & SanitizeSQL(lastname) & "')"
cn.execute(strSQL)         

set rs = cn.execute("SELECT @@Identity")
id=rs(0)
response.Redirect("details.asp?id=" & id)
ASKER CERTIFIED SOLUTION
Avatar of matija_
matija_
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
strSQL = "INSERT INTO Employees (FirstName, LastName) " _
& "VALUES ('" & Replace(Request.Form("FirstName"),"'","''") & "','" & Replace(Request.Form("LastName"),"'","''") & "')"
cn.execute(strSQL)        

set rs = cn.execute("SELECT @@Identity")
id=rs(0)
rs.close
response.Redirect("details.asp?id=" & id)
I gotta say that SELECT/UPDATE is much more bullet-proof and forgiving than INSERT method, but nonetheless, your answer is here, it's your choice which method.
Why's that?
(No expert here myself, just a novice. Just the way I have done it.  Might change my methods.)