Kevin Smith
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?
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
...
RS.Update
RS.Requery
RS.MoveLast
LastId = RS("emplyee_id")
RS.Close
Response.Redirect "details.asp?id=" LastId
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)
& "VALUES ('" & SanitizeSQL(firstname) & "','" & SanitizeSQL(lastname) & "')"
cn.execute(strSQL)
set rs = cn.execute("SELECT @@Identity")
id=rs(0)
response.Redirect("details
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
strSQL = "INSERT INTO Employees (FirstName, LastName) " _
& "VALUES ('" & Replace(Request.Form("Firs tName"),"' ","''") & "','" & Replace(Request.Form("Last Name"),"'" ,"''") & "')"
cn.execute(strSQL)
set rs = cn.execute("SELECT @@Identity")
id=rs(0)
rs.close
response.Redirect("details .asp?id=" & id)
& "VALUES ('" & Replace(Request.Form("Firs
cn.execute(strSQL)
set rs = cn.execute("SELECT @@Identity")
id=rs(0)
rs.close
response.Redirect("details
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.)
(No expert here myself, just a novice. Just the way I have done it. Might change my methods.)
say it is detail.aspx and accept a querystring with EmpID
then just do this
server.redirect("detail.as
or, use session
session("EmpID") = NewEmpID
server.transfer("details.a
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...