Connecting Tech Pros Worldwide Help | Site Map

transferring record from one asp file to another

Member
 
Join Date: Jul 2008
Posts: 123
#1: Sep 30 '09
I have a asp file which contain all recordset from access database in a table (List Products.asp). At each row there is a link which will open another file (Update Product.asp). The open file will contain record that is selected from List Products.asp.

So, how to get the selected record from List Products.asp appear on Update Product.asp. It will appear in a text box for each field.

Here what is contain in database.

Table: Products
Field: Product ID, Product Name, Product Price

Below is code for List Products.asp

Expand|Select|Wrap|Line Numbers
  1. <%language="javascript"%>
  2. <html>
  3. <body>
  4. <% var DSN="DSN=Bakery";
  5. var Conn = Server.CreateObject("ADODB.Connection");
  6. Conn.Open(DSN);
  7.  
  8. sql="SELECT * from Products";
  9. rs=Server.CreateObject("ADODB.Recordset");
  10. rs.Open(sql,Conn);
  11.  
  12. out+="<table border=1>"
  13. out +="<tr><td>Product ID</td><td>Product Name</td><td>Price</td></tr>";
  14.  
  15. while(!(rs.EOF))
  16. {
  17. out +="<tr><td><%rs("Product ID")%></td><td><%rs("Product Name")%></td><td><%rs("Product Price")%></td><td><a href="Update Product.asp"></a></td></tr>"
  18.  
  19. rs.move(1);
  20. }
  21.  
  22. out +="</table>"
  23. rs.Close();
  24. Response.write(out);
  25.  
  26. %>
  27. </body>
  28. </html>
  29.  
  30.  
I need help to create the sql for Update Product.asp and how to transfer record from List Products.asp to Update Product.asp
codegecko's Avatar
Moderator
 
Join Date: May 2007
Location: United Kingdom
Posts: 395
#2: Oct 1 '09

re: transferring record from one asp file to another


Hi puT3,

Your "Update Product.asp" file should simply be able to accept a querystring parameter so then you can do this:

Expand|Select|Wrap|Line Numbers
  1. Integer iProduct = CInt(Request.QueryString("pid"))
  2. ' Then declare your SQL as:
  3. strSQL = "SELECT * FROM Product WHERE ProductID = " & iProduct
  4.  
That'll then grab the individual product record from the table.
Now to actually pass the product ID to that page, you have to change the hyperlink in "List Products.asp" to read this:
Expand|Select|Wrap|Line Numbers
  1. out +="<tr><td><%rs("Product ID")%></td><td><%rs("Product Name")%></td><td><%rs("Product Price")%></td><td><a href="Update Product.asp?pid=<%rs("Product ID")%>"></a></td></tr>"
  2.  
Note that your Product ID has now been appended to the end of the URL as a parameter called "pid", which the Request.QueryString method in the Update Product.asp file can read and subsequently use to query your DB.

Hope this helps.

codegecko
Reply