Solved

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

Posted on 2011-03-16
8
326 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

912 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

24 Experts available now in Live!

Get 1:1 Help Now