Capturing a recordset value

D

Dave

I have a page that runs a query that displays the expected results, a single
record

I want to the value of one of the fields and pass to another page for
display (a confirmation page).

I want to do this is asp.

The question: How do I capture the value of a recordset to pass it on?

The recordset's syntax is <%=rs("Course")%>

Is this completed through a hidden field in a form, or is a variable
assigned to this recordset?

I am stuck.

Dave
 
J

Jim Buyens

Typically, you would pass the value in a query string.
Here's a simple example using a hyperlink.

<a href="courseinfo.asp?course=<%=rs("Course")%>">
Course Info</a>

Of, if you want to jump automatically only if the course
is found, code

tmpCourse = ""
if not rs.eof then
tmpcourse = rs("course")
end if
rs.close
cn.close
if tmpCourse <> "" then
response.redirect "courseinfo.asp?course=" & tmpCourse"
end if

In either case, the courseinfo.asp page would
retrieve the course value by using the expression
Request.QueryString("course").

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
D

Dave

Thanks Jim:

I need a little more info: I use the example

Ex1
a href="courseinfo.asp?course=<%=rs("Course")%>">Course Info</a> to pass one
value now.
What would be the syntax to pass 2 values (Course and Start Date)?

Ex2
The Response.Redirect example: response.redirect "courseinfo.asp?course=" &
tmpCourse
This is similar to Ex1 and I know how to redirect, but not how to pass 2
values.

Can the recordset value be sent in a hidden form field, and if so how?

Can you help a little more?

Dave
 
T

Thomas A. Rowe

Another option:

On Pg1

Session("Course") = rs("course")
Session("StartDate") = rs("StartDate")

response.redirect "courseinfo.asp"

Then on courseinfo.asp grab the two session variables

Course = Session("Course")
StartDate = Session("StartDate")

Then to display, etc.

<%=Course%>
<%=StartDate%>

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 
J

Jim Buyens

Responses interspersed...

Dave said:
Thanks Jim:

I need a little more info: I use the example

Ex1
a href="courseinfo.asp?course=<%=rs("Course")%>">Course Info</a> to pass one
value now.
What would be the syntax to pass 2 values (Course and Start Date)?

Well, you need to create a URL like
courseinfo.asp?course=math101&stdate=20040731
so the code would be

response.redirect "courseinfo.asp?course=" & tmpCourse & _
"&stdate=" & tmpstdate

If, however, your start date contains slashes or other reserved
characters, you would need to code:

response.redirect "courseinfo.asp?course=" & tmpCourse & _
"&stdate=" & server.urlencode(tmpstdate)

The server.urlencode methods translats / to %2F and so forth. ASP
translates these back to / and so forth on input.
Ex2
The Response.Redirect example: response.redirect "courseinfo.asp?course=" &
tmpCourse
This is similar to Ex1 and I know how to redirect, but not how to pass 2
values.

Same as above.
Can the recordset value be sent in a hidden form field, and if so how?

Can you help a little more?

Dave

If you have

<form method="POST" action="courseinfo.asp">
<input type="hidden" name="course">
<input type="hidden" name="stdate">
....
</form>

then you would have to write a script like:

<script>
function subForm(course, stdate){
document.forms[0].course.value=course;
document.forms[0].stdate.value=stdate;
document.forms[0].submit();
}
</script>

And then invoke the script by sending code to the browser, as in:

tmpCourse = ""
if not rs.eof then
tmpcourse = rs("course")
tmpstdate = rs("stdate")
end if
rs.close
cn.close
if tmpCourse <> "" then
response.write "<script>subForm('" & tmpcourse & _
"','" & tmpstdate & "');</script>"
end if

The courseinfo.asp page would then receive the values in
Request.Form("course") and Request.Form("stdate")

However, why would you go to this extra trouble? True, with the hidden
form fields, the visitor doesn't see the query string values in the
Address bar. But don't those values appear on the selection page, the
query page, or both anyway? It doesn't seem like they'd be a big
secret. And the visitor could see them anyway, by doing a View Source.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
D

Dave

Thank you.

I will try these Monday, they sound like solutions.

Dave

Jim Buyens said:
Responses interspersed...

"Dave" <[email protected]> wrote in message
Thanks Jim:

I need a little more info: I use the example

Ex1
a href="courseinfo.asp?course=<%=rs("Course")%>">Course Info</a> to pass one
value now.
What would be the syntax to pass 2 values (Course and Start Date)?

Well, you need to create a URL like
courseinfo.asp?course=math101&stdate=20040731
so the code would be

response.redirect "courseinfo.asp?course=" & tmpCourse & _
"&stdate=" & tmpstdate

If, however, your start date contains slashes or other reserved
characters, you would need to code:

response.redirect "courseinfo.asp?course=" & tmpCourse & _
"&stdate=" & server.urlencode(tmpstdate)

The server.urlencode methods translats / to %2F and so forth. ASP
translates these back to / and so forth on input.
Ex2
The Response.Redirect example: response.redirect "courseinfo.asp?course=" &
tmpCourse
This is similar to Ex1 and I know how to redirect, but not how to pass 2
values.

Same as above.
Can the recordset value be sent in a hidden form field, and if so how?

Can you help a little more?

Dave

If you have

<form method="POST" action="courseinfo.asp">
<input type="hidden" name="course">
<input type="hidden" name="stdate">
...
</form>

then you would have to write a script like:

<script>
function subForm(course, stdate){
document.forms[0].course.value=course;
document.forms[0].stdate.value=stdate;
document.forms[0].submit();
}
</script>

And then invoke the script by sending code to the browser, as in:

tmpCourse = ""
if not rs.eof then
tmpcourse = rs("course")
tmpstdate = rs("stdate")
end if
rs.close
cn.close
if tmpCourse <> "" then
response.write "<script>subForm('" & tmpcourse & _
"','" & tmpstdate & "');</script>"
end if

The courseinfo.asp page would then receive the values in
Request.Form("course") and Request.Form("stdate")

However, why would you go to this extra trouble? True, with the hidden
form fields, the visitor doesn't see the query string values in the
Address bar. But don't those values appear on the selection page, the
query page, or both anyway? It doesn't seem like they'd be a big
secret. And the visitor could see them anyway, by doing a View Source.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------


 
Top