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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset problem

Status
Not open for further replies.

blackcat9000

Programmer
Feb 25, 2003
15
0
0
GB
Hi yer bro's.

My problem is i am trying to produce results based on a selection.

Now it brings up the first page of the results ok, but if there are more that one page of results and i proceed to see further pages I seem to lose the recordset connection and it brings me back to my main menu page.


example below:

<%

Dim Con
Dim rsPage
Dim Page
Dim RowCount
Dim PageCounter
Dim u_where
Dim u_search

u_search=request.form("u_search")
u_where=request.form("u_where")
if u_search = "" or u_where= "" then
response.redirect "main.asp"
end if


Page = Request.QueryString("Page")


If Page = "" then Page = 1

RowCount = 0


DSNtemp = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("Samples.mdb")
set conn = CreateObject("ADODB.Connection")
conn.open DSNtemp
Set rsPage = Server.CreateObject("ADODB.Recordset")

lsSQL = "select * from Sample where " & u_where &" like '%%"& u_search & "%%'"

rsPage.CursorType = 3 'adOpenStatic
rsPage.PageSize = 10
rsPage.Open lsSQL, Conn



TotalRecs = rsPage.recordcount
TotalPages = cInt(rsPage.pagecount)
rsPage.AbsolutePage = cInt(Page)
%>

<%
If Response.IsClientConnected = true then

response.write "<td width = 100% bgcolor = #ffffff><b><center><font face=Verdana size=2>The following results met your search criteria for <font color=#ff0000>'"& u_search & "'</b></center></td>"
response.write "<br><Font face='arial' size=2><font color=#000000>There are " & TotalRecs & " entries in " & TotalPages & " pages</font><br>"
response.write "<br></br>"

Do while not rsPage.eof and RowCount < rsPage.PageSize

ID = rsPage("ID")
Name = rsPage("Name")
%>
<%
rsPage.Movenext
RowCount = RowCount + 1
Loop


For PageCounter = 1 to rsPage.PageCount
Response.Write "<a href='results3.asp?Page=" & PageCounter & "&u_search=" & Server.URLEncode(u_search) & "'>" & PageCounter & "</a> "
Next
rsPage.Close
set rsPage = Nothing
End if
%>



Can any guru help?


Thanks in advance
 
I'm not convinced a guru is necessary :eek:)

Code:
u_search=request("u_search")
u_where=request("u_where")

your links are using request.querystring, your code request.form - so detect both

simon
 
being a bit of a novice simon, can you put it into a example.

thanks in advance
 
The idea behind using just Request("u_search") is tat b not pecifying .Form or .Querystring the sstem will look through each of the Request colle ctions for the item you named.
Right now when you hit the scond page your u_search variable is being passed as a querystring, but you are still attempting to read it from Request.Form.

if you replace Request.Form with just Request as simon suggested, it will find the collection tht has a value (in this case QueryString) and pull the value in for you. This method is slightly inefficient as it has to search the Request.Form collection and then the Request.QueryString collection, but it shouldn't hurt you in a noticeable fashion.

One other thing to note, you are not passing your u_where variable in the next page link. Looking at your code, you should be getting ADO error messages when you try to execute your SQL statement because portions of it are missing and it won't be synctactically correct (until you fix the u_where and u_search stuff).

Hope this clarifies it for you,

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top