Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-16
8
Medium Priority
?
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 59

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
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!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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