Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Variables

Status
Not open for further replies.

AGNEW2PRG

Technical User
Aug 5, 2003
98
AE
Hi,

Can anybody help me here pls? The code below writes the contents to a access db. However, how do i pass the "strPID" variable to the next page?

Thanks in advance..

<%
'Dimension variables
Dim adoCon
Dim rsAddProperty
Dim strSQL
Dim strPID

Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("property.mdb")

Set rsAddProperty = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM TBL_PROP;"

rsAddProperty.LockType = 3

rsAddProperty.Open strSQL, adoCon

rsAddProperty.AddNew

rsAddProperty.Fields("ADDRESS") = Request.Form("ADDRESS")
rsAddProperty.Fields("POSTCODE") = Request.Form("POSTCODE")
rsAddProperty.Fields("DESCRIPTION") = Request.Form("DESCRIPTION")

strPID=rsAddProperty("PID")

'Reset server objects
rsAddProperty.Close
Set rsAddProperty = Nothing
Set adoCon = Nothing

Response.Redirect "page2.asp"
%>
 
There are 2 easy ways to do this:
Code:
<%
'Dimension variables
Dim adoCon
Dim rsAddProperty
Dim strSQL
Dim strPID

Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("property.mdb")

Set rsAddProperty = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM TBL_PROP;"

rsAddProperty.LockType = 3

rsAddProperty.Open strSQL, adoCon

rsAddProperty.AddNew

rsAddProperty.Fields("ADDRESS") = Request.Form("ADDRESS")
rsAddProperty.Fields("POSTCODE") = Request.Form("POSTCODE")
rsAddProperty.Fields("DESCRIPTION") = Request.Form("DESCRIPTION")

strPID=rsAddProperty("PID")

'Reset server objects
rsAddProperty.Close
Set rsAddProperty = Nothing
Set adoCon = Nothing

Response.Redirect "page2.asp?p_id=" & strPID
%>
With this method you can then access the strPID value on page2.asp as follows:
Code:
<%
Response.Write(Request.QueryString("p_id"))
%>

The other method is to save it in a session variable:
Code:
<%
'Dimension variables
Dim adoCon
Dim rsAddProperty
Dim strSQL
Dim strPID

Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("property.mdb")

Set rsAddProperty = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM TBL_PROP;"

rsAddProperty.LockType = 3

rsAddProperty.Open strSQL, adoCon

rsAddProperty.AddNew

rsAddProperty.Fields("ADDRESS") = Request.Form("ADDRESS")
rsAddProperty.Fields("POSTCODE") = Request.Form("POSTCODE")
rsAddProperty.Fields("DESCRIPTION") = Request.Form("DESCRIPTION")

Session("p_id") = rsAddProperty("PID")

'Reset server objects
rsAddProperty.Close
Set rsAddProperty = Nothing
Set adoCon = Nothing

Response.Redirect "page2.asp"
%>
And on page2.asp you would access it like this:
Code:
<%
Response.Write(Session("p_id"))
%>

Take Care,
Mike
 
Thanks Mike,

I started working with the session variable..

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top