Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-16
8
Medium Priority
?
346 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 61

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
LVL 6

Accepted Solution

by:
matija_ earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 informatio…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

879 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