Solved

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

Posted on 2011-03-16
8
334 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 53

Expert Comment

by:Huseyin KAHRAMAN
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
Technology Partners: 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 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

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

Suggested Solutions

Title # Comments Views Activity
Html Table Looping (part 2) 5 41
Asp response.write to clients 6 46
JQuery on multiple lines 3 47
JQuery Data Table Default Sort 2 31
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 was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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