Solved

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

Posted on 2011-03-16
8
324 Views
Last Modified: 2012-05-11
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?
0
Comment
Question by:Kevin Smith
8 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 35151365
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...

0
 
LVL 6

Expert Comment

by:matija_
ID: 35152061
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
0
 

Author Comment

by:Kevin Smith
ID: 35152147
Where would that go?
0
 
LVL 3

Expert Comment

by:harris9999
ID: 35152404
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)
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 6

Accepted Solution

by:
matija_ earned 500 total points
ID: 35152933
Assuming you have your connection provider open, here's a fictional example that would do what you asked for:

SQL = "SELECT Id, Name, Surname, Whatever, Fields, You, Have FROM Employees"
RS.Open SQL, Conn, 3, 3

RS.AddNew
RS(1) = Request.Form("Name")
RS(2) = Request.Form("Surname")
RS(3) = Request.Form("Whatever")
RS(4) = Request.Form("Fields")
RS(5) = Request.Form("You")
RS(6) = Request.Form("Have")
RS.Update
RS.Requery
RS.MoveLast
LastId = RS(0) 'this is field with Id
RS.Close

Response.Redirect "yourpage.asp?id=" LastId
0
 
LVL 3

Expert Comment

by:harris9999
ID: 35152957
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)
0
 
LVL 6

Expert Comment

by:matija_
ID: 35155548
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.
0
 
LVL 3

Expert Comment

by:harris9999
ID: 35155579
Why's that?
(No expert here myself, just a novice. Just the way I have done it.  Might change my methods.)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now