Home > SQL Development > rstSearch.RecordCount works but get no records returned in table

rstSearch.RecordCount works but get no records returned in table



<i><b>Originally posted by : Lee Farrant (leefarrant@hotmail.com)</b></i><br />below is some sample code which I have added to. <br /><br />Since I changed from a dsnless to a DSN connection I am having some problems. the count of records get displayed in my webpages fine so the RecordCount works so the SQL must be running, but it will not display the records in a table. It does not error. Just displays the table header cells.<br /><br />Can anyone see what I have done wrong.<br /><br />Thanks<br />Lee<br /> <br /><br /><%<br />' Constants ripped from adovbs.inc:<br /> Const adOpenStatic = 3<br /> Const adLockReadOnly = 1<br /> Const adCmdText = &H0001<br /><br />' Our own constants:<br />Const PAGE_SIZE = 5 ' The size of our pages.<br /><br />' Declare our variables... always good practice!<br />Dim strURL ' The URL of this page so the form will work<br /> ' no matter what this file is named.<br /><br />Dim cnnSearch ' ADO connection<br />Dim rstSearch ' ADO recordset<br />Dim strDBPath ' path to our Access database (*.mdb) file<br /><br />Dim strSQL ' The SQL Query we build on the fly<br />Dim ukstrSQL<br />Dim londonstrSQL<br />Dim strSearch ' The text being looked for<br /><br />Dim iPageCurrent ' The page we're currently on<br />Dim iPageCount ' Number of pages of records<br />Dim iRecordCount ' Count of the records returned<br />Dim I ' Standard looping variable<br /><br />Dim county<br />Dim londonzone<br />Dim weeklyrent<br /><br />strURL = Request.ServerVariables("URL")<br /><br />county = Request.QueryString("county")<br />londonzone = Request.Querystring("londonzone")<br />weeklyrent = Request.Querystring("weeklyrent")<br />gocheck = Request.Querystring("county") + Request.Querystring("londonzone")<br />searchoptions = Request.QueryString("searchoptions")<br /><br />' Retrieve page to show or default to the first<br />If Request.QueryString("page") = "" Then<br /> iPageCurrent = 1<br />Else<br /> iPageCurrent = CInt(Request.QueryString("page"))<br />End If<br /><br />' Since I'm doing this all in one page I need to see if anyone<br />' has searched for something. If they have we hit the DB.<br />' O/W I just show the search form and quit.<br />%><br /><form action="<%= strURL %>" method="get" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1"><br /><p align="right"><br /><img border="0" src="../images/signin.gif"><a target="_top" href="http://www.blabla.com/"><img border="0" src="../images/Room_Logo_trans.gif" align="left"></a> <br><br /> </p><br /><p align="left"><br /><br><br /><!--webbot bot="Validation" s-display-name="UK County" b-value-required=""TRUE"" --><select size="1" name="county"><br /> <br /><option selected value="none">UK County</option><br /><option value="Avon">England Avon</option><br /><option value="Bedfordshire">England Bedfordshire</option><br /><option value="Berkshire">England Berkshire</option><br /><option value="Buckinghamshire">England Buckinghamshire</option><br /><option value="Cambridgeshire">England Cambridgeshire</option><br /><option value="Cheshire">England Cheshire</option><br /><option value="Cleveland">England Cleveland</option><br /><option value="Cornwall">England Cornwall</option><br /><option value="Cumbria">England Cumbria</option><br /><option value="Derbyshire">England Derbyshire</option><br /><option value="Devon">England Devon</option><br /><option value="Dorset">England Dorset</option><br /><option value="Durham">England Durham</option><br /><option value="East Sussex">England East Sussex</option><br /><option value="Essex">England Essex</option><br /><option value="Gloucestershire">England Gloucestershire</option><br /><option value="Greater Manchester">England Greater Manchester</option><br /><option value="Hampshire">England Hampshire</option><br /><option value="Herefordshire">England Herefordshire</option><br /><option value="Humberside">England Humberside</option><br /><option value="Isle of Wight">England Isle of Wight</option><br /><option value="Isle of Scilly">England Isle of Scilly</option><br /><option value="Kent">England Kent</option><br /><option value="Lancashire">England Lancashire</option><br /><option value="Leicestershire">England Leicestershire</option><br /><option value="Lincolnshire">England Lincolnshire</option><br /><option value="Merseyside">England Merseyside</option><br /><option value="Norfolk">England Norfolk</option><br /><option value="North Yorkshire">England North Yorkshire</option><br /><option value="Northamptonshire">England Northamptonshire</option><br /><option value="Northumberland">England Northumberland</option><br /><option value="Nottinghamshire">England Nottinghamshire<br /><option value="Oxfordshire">England Oxfordshire</option><br /><option value="Rutland">England Rutland</option><br /><option value="Shropshire">England Shropshire</option><br /><option value="Somerset">England Somerset</option><br /><option value="South Yorkshire">England South Yorkshire</option><br /><option value="Staffordshire">England Staffordshire</option><br /><option value="Suffolk">England Suffolk</option><br /><option value="Surrey">England Surrey</option><br /><option value="Tyne and Wear">England Tyne and Wear</option><br /><option value="Warwickshire">England Warwickshire</option><br /><option value="West Midlands">England West Midlands</option><br /><option value="West Sussex">England West Sussex</option><br /><option value="West Yorkshire">England West Yorkshire</option><br /><option value="Wiltshire">England Wiltshire</option><br /><option value="Worcestershire">England Worcestershire</option><br /><option value="Clwyd">Wales Clwyd</option><br /><option value="Dyfed">Wales Dyfed</option><br /><option value="Gwent">Wales Gwent</option><br /><option value="Gwynedd County">Wales Gwynedd County</option><br /><option value="Mid Glamorgan">Wales Mid Glamorgan</option><br /><option value="Powys">Wales Powys</option><br /><option value="South Glamorgan">Wales South Glamorgan</option><br /><option value="West Glamorgan">Wales West Glamorgan</option><br /><option value="Borders">Scotland Borders</option><br /><option value="Central">Scotland Central</option><br /><option value="Dumfries and Galloway">Scotland Dumfries and Galloway</option><br /><option value="Fife">Scotland Fife</option><br /><option value="Grampian">Scotland Grampian</option><br /><option value="Highlands and Islands">Scotland Highlands and Islands</option><br /><option value="Lothian">Scotland Lothian</option><br /><option value="Strathclyde">Scotland Strathclyde</option><br /><option value="Tayside">Scotland Tayside</option><br /><option value="County Antrim">Northern Ireland County Antrim</option><br /><option value="County Armagh">Northern Ireland County Armagh</option><br /><option value="County Down">Northern Ireland County Down</option><br /><option value="County Fermanagh">Northern Ireland County Fermanagh</option><br /><option value="County Londonderry">Northern Ireland County Londonderry</option><br /><option value="County Tyrone">Northern Ireland County Tyrone</option><br /> <br /> <br /> </select> <font face="Arial" size="2">or</font><br /> <select size="1" name="londonzone"><br /> <option selected value="none">London Zone</option><br /> <option>1</option><br /> <option>2</option><br /> <option>3</option><br /> <option>4</option><br /> <option>5</option><br /> <option>6</option><br /> </select> <font size="2" face="Arial">and</font><br /><!--webbot bot="Validation" s-display-name="Max. Weekly Rent" b-value-required=""TRUE"" b-disallow-first-item=""TRUE"" --><select size="1" name="weeklyrent"><br /><option selected>Max. Weekly Rent</option><br /><option>40</option><br /><option>50</option><br /><option>60</option><br /><option>70</option><br /><option>80</option><br /><option>90</option><br /><option>100</option><br /><option>110</option><br /><option>120</option><br /><option>130</option><br /><option>140</option><br /><option>150</option><br /><option>160</option><br /><option>170</option><br /><option>180</option><br /><option>190</option><br /><option>200</option><br /><option>210</option><br /><option>220</option><br /><option>230</option><br /><option>240</option><br /><option>250</option><br /><option>260</option><br /></select><font size="2" face="Arial"><br><br />Search:<br /> <input type="radio" value="all" checked name="searchoptions"> All<br /> <input type="radio" name="searchoptions" value="professionals">Professionals<br /> <input type="radio" name="searchoptions" value="students"> Students <br /> <input type="radio" name="searchoptions" value="lg"> lg<br><br /></font> <input type="submit" value="Search" name="submit" /><br /><input type="reset" value="Reset" name="B1"></p><br /><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="903"><br /> <tr><br /> <td width="901" colspan="3"><br /> <p align="left"> <hr color="#FF9900" size="1"><br /> </td><br /> </tr><br /> <tr><br /> <td width="113"><br /> <b><font face="Arial" size="2"><br /> <a target="_top" href="http://www.blabla.com/professionals/"><br /> Professionals</a> </font></b></td><br /> <td width="110"><br /> <b><font face="Arial" size="2"> <br /> <a target="_top" href="http://www.blabla.com/students/">Students</a></font></b></td><br /> <td width="680"><br /> <font face="Arial" size="2"><br /> <b><br /> <a target="_top" href="http://www.blabla.com/lg/">lg</a> </b><br /> (Professionals & Students)</font></td><br /> </tr><br /></table><br /></form><br /> <%<br /><br />If gocheck <> "nonenone" Then<br /> ' MapPath of virtual database file path to a physical path.<br /> ' If you want you could hard code a physical path here.<br /> ' strDBPath = Server.MapPath("test.mdb")<br /><br /><br /> ' Create an ADO Connection to connect to the sample database.<br /> ' We're using OLE DB but you could just as easily use ODBC or a DSN.<br /> Set cnnSearch = Server.CreateObject("ADODB.Connection")<br /> cnnSearch.open "DSN=profiles"<br /> <br /> ' This line is for the Access sample database:<br /> ' cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"<br /><br /> ' We're actually using SQL Server so we use this line instead:<br /> ' cnnSearch.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _<br /> ' & "Initial Catalog=samples;User Id=samples;Password=password;" _<br /> ' & "Connect Timeout=15;Network Library=dbmssocn;"<br /> <br /> dim searchcat<br /> select case searchoptions<br /> case "all"<br /> searchcat = ""<br /> case "professionals"<br /> searchcat = " and category2 = 'professionals'"<br /> case "students"<br /> searchcat = " and category2 = 'students'"<br /> case "lg"<br /> searchcat = " and category2 = 'lg'"<br /> end select<br /> <br /> dim searchareacat<br /> searchareacat = " county =" & "'" & county & "'" & " and category = 'uk'"<br /> <br /> select case county <br /> case "none"<br /> searchareacat = " londonzone = " & londonzone & " and category = 'london'"<br /> end select<br /> <br /> ' strSQL = "SELECT * " & "FROM roomprofiles " & "where londonzone = " & londonzone & " and weeklyrent <=" & weeklyrent & searchcat<br /> <br /> strSQL = "SELECT category2,id,addeddate,county,londonzone,location, weeklyrent,gender,map,preferredcontactmethod,mobil e,telephone,email " & "FROM roomprofiles " _<br /> & "where " & searchareacat & " and weeklyrent <=" & weeklyrent & searchcat & " and date() <= expireDate"<br /> <br /> ' Execute our query using the connection object. It automatically<br /> ' creates and returns a recordset which we store in our variable.<br /> <br /> Set rstSearch = Server.CreateObject("ADODB.Recordset")<br /> rstSearch.ActiveConnection = cnnSearch<br /> <br /> rstSearch.PageSize = PAGE_SIZE<br /> rstSearch.CacheSize = PAGE_SIZE<br /><br /> ' Open our recordset<br /> rstSearch.Open strSQL, cnnSearch, adOpenStatic, adLockReadOnly, adCmdText<br /><br /> ' Get a count of the number of records and pages<br /> ' for use in building the header and footer text.<br /> iRecordCount = rstSearch.RecordCount<br /> iPageCount = rstSearch.PageCount<br /> If iRecordCount = 0 Then<br /> ' Display no records error.<br /> %><br /> <p align="center"><br /> <b><br /> <font size="2" face="Arial">Sorry no rooms match your requirement at the <br /> moment. See our overview of <br /> available <a target="_top" href="londonsummary.asp">London</a> or <br /> <a target="_top" href="uksummary.asp">UK</a> rooms. </font><br /> <br /> </b><br /> <br /> </p><br /><p align="center"><font face="Arial" size="2"><br /><a target="_top" href="addaroom.asp">Add a Room</a> -<br /><a target="_top" href="affiliate.asp">Our Rooms on Your Site (Affiliate)</a> - <br />Room Hosting - Free Email - Free Webspace</font></p><br /><p align="center"><font size="1" face="Arial">?2002 Cyber Ethos Limited</font></p><br /><br /> <p align="center"><br /> </p><br /> <%<br /> Else<br /> Response.Write(strSQL)<br /> ' Move to the page we need to show. <br /> rstSearch.AbsolutePage = iPageCurrent<br /><br /> ' Show a quick status line letting people know where they are:<br /> %><br /> <p align="right"><br /> <%= iRecordCount %><font face="Arial" size="2"> Room(s) Found.<br /> Page <%= iPageCurrent %><br /> of <%= iPageCount %>: </font><br /> </p><br /> <%<br /> ' Display a table of the data in the recordset. We loop through the<br /> ' recordset displaying the fields from the table and using MoveNext<br /> ' to increment to the next record. We stop when we reach EOF.<br /> ' For fun I'm combining some fields and showwing you can do more then<br /> ' just spit out the data in the form it is in in the table.<br /> %><br /> <table border="0"><br /> <tr bgcolor="#fffoe8"><br /> <th><font face="Arial" size="2">Room Category</font></th><br /> <th><font face="Arial" size="2">Ref.</font></th><br /> <th><font face="Arial" size="2">Date Room Added</font></th><br /> <th><font face="Arial" size="2">County</font></th><br /> <th><font face="Arial" size="2">London Zone</font></th><br /> <th><font face="Arial" size="2">Location</font></th><br /> <th><font face="Arial" size="2">Weekly Rent</font></th><br /> <th><font face="Arial" size="2">Male or Female Wanted</font></th><br /> <th><font face="Arial" size="2">Map</font></th><br /> <th><font face="Arial" size="2">Preferred Contact Method</font></th><br /> <th><font face="Arial" size="2">Mobile</font></th><br /> <th><font face="Arial" size="2">Telephone</font></th><br /> <th><font face="Arial" size="2">Email</font></th><br /> </tr><br /> <%<br /> rowcount=0<br /> Do While Not rstSearch.EOF And rstSearch.AbsolutePage = iPageCurrent<br /> if rowcount mod 2 then <br /> bgcolor = "FFF0E8"<br /> else<br /> bgcolor = "ECFFEC"<br /> end if<br /> %><br /> <tr bgcolor="#<%=bgcolor%>"> <br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("category2").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("id").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("addeddate").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("county").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("londonzone").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("location").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("weeklyrent").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("gender").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("map").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("preferredcontactmethod").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("mobile").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("telephone").Value %> </td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("email").Value %> </td><br /> </tr><br /> <%<br /> rowcount=rowcount+1<br /> rstSearch.MoveNext<br /> Loop<br /><br /> %><br /> </table><br /> <p align="center"><br /> <%<br /> ' Now we need to show our navigation links:<br /> <br /> ' Sho "previous" and "next" page links which pass the page to<br /> ' view our search parameter. You could also use form buttons<br /> ' but I find this looks better.<br /> If iPageCurrent > 1 Then<br /> %> <font face="Arial" size="2"><br /> <a href="<%= strURL %>?county=<%= Server.URLEncode(county) %>&londonzone=<%= Server.URLEncode(londonzone) %>&weeklyrent=<%= Server.URLEncode(weeklyrent) %>&searchoptions=<%= Server.URLEncode(searchoptions) %>&page=<%= iPageCurrent - 1 %>">[<< Prev]</a><br /> <%<br /> End If<br /><br /> ' You can also show page numbers:<br /> For I = 1 To iPageCount<br /> If I = iPageCurrent Then<br /> %><br /> <%= I %><br /> <%<br /> Else<br /> %><br /> <a href="<%= strURL %>?county=<%= Server.URLEncode(county) %>&londonzone=<%= Server.URLEncode(londonzone) %>&weeklyrent=<%= Server.URLEncode(weeklyrent) %>&searchoptions=<%= Server.URLEncode(searchoptions) %>&page=<%= I %>"><%= I %></a><br /> <%<br /> End If<br /> Next 'I<br /><br /> If iPageCurrent < iPageCount Then<br /> %><br /> <a href="<%= strURL %>?county=<%= Server.URLEncode(county) %>&londonzone=<%= Server.URLEncode(londonzone) %>&weeklyrent=<%= Server.URLEncode(weeklyrent) %>&searchoptions=<%= Server.URLEncode(searchoptions) %>&page=<%= iPageCurrent + 1 %>">[Next >>]</a><br /> <%<br /> End If<br /> %> </font><br /> </p><br /><p align="center"><font face="Arial" size="2"><br /><a target="_top" href="addaroom.asp">Add a Room</a> - <br /><a target="_top" href="affiliate.asp">Our Rooms on Your <br />Site (Affiliate)</a> - Room Hosting - Free Email - Free Webspace</font></p><br /><p align="center"><font size="1" face="Arial">?2002 Cyber Ethos Limited</font></p><br /><br /><p align="center"> </p><br /><br /> </font><br /><br /> <%<br /> End If<br /><br /> ' Close our recordset and connection and dispose of the objects<br /> rstSearch.Close<br /> Set rstSearch = Nothing<br /> cnnSearch.Close<br /> Set cnnSearch = Nothing<br />End If<br />%>

    
Guest


<i><b>Originally posted by : Zeeshan Ahmad (shani_786@hotmail.com)</b></i><br />Use this line between creating recordset object and open recordset object<br /><br />"Rs.Cursor=adUserClient"<br /><br /><br />------------<br />Lee Farrant at 3/30/2002 1:29:07 PM<br /><br />below is some sample code which I have added to. <br /><br />Since I changed from a dsnless to a DSN connection I am having some problems. the count of records get displayed in my webpages fine so the RecordCount works so the SQL must be running, but it will not display the records in a table. It does not error. Just displays the table header cells.<br /><br />Can anyone see what I have done wrong.<br /><br />Thanks<br />Lee<br /> <br /><br /><%<br />' Constants ripped from adovbs.inc:<br /> Const adOpenStatic = 3<br /> Const adLockReadOnly = 1<br /> Const adCmdText = &H0001<br /><br />' Our own constants:<br />Const PAGE_SIZE = 5 ' The size of our pages.<br /><br />' Declare our variables... always good practice!<br />Dim strURL ' The URL of this page so the form will work<br /> ' no matter what this file is named.<br /><br />Dim cnnSearch ' ADO connection<br />Dim rstSearch ' ADO recordset<br />Dim strDBPath ' path to our Access database (*.mdb) file<br /><br />Dim strSQL ' The SQL Query we build on the fly<br />Dim ukstrSQL<br />Dim londonstrSQL<br />Dim strSearch ' The text being looked for<br /><br />Dim iPageCurrent ' The page we're currently on<br />Dim iPageCount ' Number of pages of records<br />Dim iRecordCount ' Count of the records returned<br />Dim I ' Standard looping variable<br /><br />Dim county<br />Dim londonzone<br />Dim weeklyrent<br /><br />strURL = Request.ServerVariables("URL")<br /><br />county = Request.QueryString("county")<br />londonzone = Request.Querystring("londonzone")<br />weeklyrent = Request.Querystring("weeklyrent")<br />gocheck = Request.Querystring("county") + Request.Querystring("londonzone")<br />searchoptions = Request.QueryString("searchoptions")<br /><br />' Retrieve page to show or default to the first<br />If Request.QueryString("page") = "" Then<br /> iPageCurrent = 1<br />Else<br /> iPageCurrent = CInt(Request.QueryString("page"))<br />End If<br /><br />' Since I'm doing this all in one page I need to see if anyone<br />' has searched for something. If they have we hit the DB.<br />' O/W I just show the search form and quit.<br />%><br /><form action="<%= strURL %>" method="get" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1"><br /><p align="right"><br /><img border="0" src="../images/signin.gif"><a target="_top" href="http://www.blabla.com/"><img border="0" src="../images/Room_Logo_trans.gif" align="left"></a> <br><br />*</p><br /><p align="left"><br /><br><br /><!--webbot bot="Validation" s-display-name="UK County" b-value-required=""TRUE"" --><select size="1" name="county"><br /> <br /><option selected value="none">UK County</option><br /><option value="Avon">England Avon</option><br /><option value="Bedfordshire">England Bedfordshire</option><br /><option value="Berkshire">England Berkshire</option><br /><option value="Buckinghamshire">England Buckinghamshire</option><br /><option value="Cambridgeshire">England Cambridgeshire</option><br /><option value="Cheshire">England Cheshire</option><br /><option value="Cleveland">England Cleveland</option><br /><option value="Cornwall">England Cornwall</option><br /><option value="Cumbria">England Cumbria</option><br /><option value="Derbyshire">England Derbyshire</option><br /><option value="Devon">England Devon</option><br /><option value="Dorset">England Dorset</option><br /><option value="Durham">England Durham</option><br /><option value="East Sussex">England East Sussex</option><br /><option value="Essex">England Essex</option><br /><option value="Gloucestershire">England Gloucestershire</option><br /><option value="Greater Manchester">England Greater Manchester</option><br /><option value="Hampshire">England Hampshire</option><br /><option value="Herefordshire">England Herefordshire</option><br /><option value="Humberside">England Humberside</option><br /><option value="Isle of Wight">England Isle of Wight</option><br /><option value="Isle of Scilly">England Isle of Scilly</option><br /><option value="Kent">England Kent</option><br /><option value="Lancashire">England Lancashire</option><br /><option value="Leicestershire">England Leicestershire</option><br /><option value="Lincolnshire">England Lincolnshire</option><br /><option value="Merseyside">England Merseyside</option><br /><option value="Norfolk">England Norfolk</option><br /><option value="North Yorkshire">England North Yorkshire</option><br /><option value="Northamptonshire">England Northamptonshire</option><br /><option value="Northumberland">England Northumberland</option><br /><option value="Nottinghamshire">England Nottinghamshire<br /><option value="Oxfordshire">England Oxfordshire</option><br /><option value="Rutland">England Rutland</option><br /><option value="Shropshire">England Shropshire</option><br /><option value="Somerset">England Somerset</option><br /><option value="South Yorkshire">England South Yorkshire</option><br /><option value="Staffordshire">England Staffordshire</option><br /><option value="Suffolk">England Suffolk</option><br /><option value="Surrey">England Surrey</option><br /><option value="Tyne and Wear">England Tyne and Wear</option><br /><option value="Warwickshire">England Warwickshire</option><br /><option value="West Midlands">England West Midlands</option><br /><option value="West Sussex">England West Sussex</option><br /><option value="West Yorkshire">England West Yorkshire</option><br /><option value="Wiltshire">England Wiltshire</option><br /><option value="Worcestershire">England Worcestershire</option><br /><option value="Clwyd">Wales Clwyd</option><br /><option value="Dyfed">Wales Dyfed</option><br /><option value="Gwent">Wales Gwent</option><br /><option value="Gwynedd County">Wales Gwynedd County</option><br /><option value="Mid Glamorgan">Wales Mid Glamorgan</option><br /><option value="Powys">Wales Powys</option><br /><option value="South Glamorgan">Wales South Glamorgan</option><br /><option value="West Glamorgan">Wales West Glamorgan</option><br /><option value="Borders">Scotland Borders</option><br /><option value="Central">Scotland Central</option><br /><option value="Dumfries and Galloway">Scotland Dumfries and Galloway</option><br /><option value="Fife">Scotland Fife</option><br /><option value="Grampian">Scotland Grampian</option><br /><option value="Highlands and Islands">Scotland Highlands and Islands</option><br /><option value="Lothian">Scotland Lothian</option><br /><option value="Strathclyde">Scotland Strathclyde</option><br /><option value="Tayside">Scotland Tayside</option><br /><option value="County Antrim">Northern Ireland County Antrim</option><br /><option value="County Armagh">Northern Ireland County Armagh</option><br /><option value="County Down">Northern Ireland County Down</option><br /><option value="County Fermanagh">Northern Ireland County Fermanagh</option><br /><option value="County Londonderry">Northern Ireland County Londonderry</option><br /><option value="County Tyrone">Northern Ireland County Tyrone</option><br /> <br /> <br /> </select>* <font face="Arial" size="2">or</font><br /> <select size="1" name="londonzone"><br /> <option selected value="none">London Zone</option><br /> <option>1</option><br /> <option>2</option><br /> <option>3</option><br /> <option>4</option><br /> <option>5</option><br /> <option>6</option><br /> </select> <font size="2" face="Arial">and</font><br /><!--webbot bot="Validation" s-display-name="Max. Weekly Rent" b-value-required=""TRUE"" b-disallow-first-item=""TRUE"" --><select size="1" name="weeklyrent"><br /><option selected>Max. Weekly Rent</option><br /><option>40</option><br /><option>50</option><br /><option>60</option><br /><option>70</option><br /><option>80</option><br /><option>90</option><br /><option>100</option><br /><option>110</option><br /><option>120</option><br /><option>130</option><br /><option>140</option><br /><option>150</option><br /><option>160</option><br /><option>170</option><br /><option>180</option><br /><option>190</option><br /><option>200</option><br /><option>210</option><br /><option>220</option><br /><option>230</option><br /><option>240</option><br /><option>250</option><br /><option>260</option><br /></select><font size="2" face="Arial"><br><br />Search:<br /> <input type="radio" value="all" checked name="searchoptions"> All<br /> <input type="radio" name="searchoptions" value="professionals">Professionals<br /> <input type="radio" name="searchoptions" value="students"> Students*<br /> <input type="radio" name="searchoptions" value="lg"> lg<br><br /></font>*<input type="submit" value="Search" name="submit" /><br /><input type="reset" value="Reset" name="B1"></p><br /><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="903"><br /> <tr><br /> <td width="901" colspan="3"><br /> <p align="left">*<hr color="#FF9900" size="1"><br /> </td><br /> </tr><br /> <tr><br /> <td width="113"><br /> <b><font face="Arial" size="2"><br /> <a target="_top" href="http://www.blabla.com/professionals/"><br /> Professionals</a>* </font></b></td><br /> <td width="110"><br /> <b><font face="Arial" size="2">**<br /> <a target="_top" href="http://www.blabla.com/students/">Students</a></font></b></td><br /> <td width="680"><br /> <font face="Arial" size="2"><br /> <b><br /> <a target="_top" href="http://www.blabla.com/lg/">lg</a> </b><br /> (Professionals & Students)</font></td><br /> </tr><br /></table><br /></form><br />*<%<br /><br />If gocheck <> "nonenone" Then<br /> ' MapPath of virtual database file path to a physical path.<br /> ' If you want you could hard code a physical path here.<br /> ' strDBPath = Server.MapPath("test.mdb")<br /><br /><br /> ' Create an ADO Connection to connect to the sample database.<br /> ' We're using OLE DB but you could just as easily use ODBC or a DSN.<br /> Set cnnSearch = Server.CreateObject("ADODB.Connection")<br /> cnnSearch.open "DSN=profiles"<br /> <br /> ' This line is for the Access sample database:<br /> ' cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"<br /><br /> ' We're actually using SQL Server so we use this line instead:<br /> ' cnnSearch.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _<br /> ' & "Initial Catalog=samples;User Id=samples;Password=password;" _<br /> ' & "Connect Timeout=15;Network Library=dbmssocn;"<br /> <br /> dim searchcat<br /> select case searchoptions<br /> case "all"<br /> searchcat = ""<br /> case "professionals"<br /> searchcat = " and category2 = 'professionals'"<br /> case "students"<br /> searchcat = " and category2 = 'students'"<br /> case "lg"<br /> searchcat = " and category2 = 'lg'"<br /> end select<br /> <br /> dim searchareacat<br /> searchareacat = " county =" & "'" & county & "'" & " and category = 'uk'"<br /> <br /> select case county <br /> case "none"<br /> searchareacat = " londonzone = " & londonzone & " and category = 'london'"<br /> end select<br /> <br /> ' strSQL = "SELECT * " & "FROM roomprofiles " & "where londonzone = " & londonzone & " and weeklyrent <=" & weeklyrent & searchcat<br /> <br /> strSQL = "SELECT category2,id,addeddate,county,londonzone,location, weeklyrent,gender,map,preferredcontactmethod,mobil e,telephone,email " & "FROM roomprofiles " _<br /> & "where " & searchareacat & " and weeklyrent <=" & weeklyrent & searchcat & " and date() <= expireDate"<br /> <br /> ' Execute our query using the connection object. It automatically<br /> ' creates and returns a recordset which we store in our variable.<br /> <br /> Set rstSearch = Server.CreateObject("ADODB.Recordset")<br /> rstSearch.ActiveConnection = cnnSearch<br /> <br /> rstSearch.PageSize = PAGE_SIZE<br /> rstSearch.CacheSize = PAGE_SIZE<br /><br /> ' Open our recordset<br /> rstSearch.Open strSQL, cnnSearch, adOpenStatic, adLockReadOnly, adCmdText<br /><br /> ' Get a count of the number of records and pages<br /> ' for use in building the header and footer text.<br /> iRecordCount = rstSearch.RecordCount<br /> iPageCount = rstSearch.PageCount<br /> If iRecordCount = 0 Then<br /> ' Display no records error.<br /> %><br /> <p align="center"><br /> <b><br /> <font size="2" face="Arial">Sorry no rooms match your requirement at the <br /> moment. See our overview of <br /> available <a target="_top" href="londonsummary.asp">London</a> or <br /> <a target="_top" href="uksummary.asp">UK</a> rooms. </font><br /> <br /> </b><br /> <br /> </p><br /><p align="center"><font face="Arial" size="2"><br /><a target="_top" href="addaroom.asp">Add a Room</a> -<br /><a target="_top" href="affiliate.asp">Our Rooms on Your Site (Affiliate)</a> - <br />Room Hosting - Free Email - Free Webspace</font></p><br /><p align="center"><font size="1" face="Arial">?2002 Cyber Ethos Limited</font></p><br /><br /> <p align="center"><br /> *</p><br /> <%<br /> Else<br /> Response.Write(strSQL)<br /> ' Move to the page we need to show. <br /> rstSearch.AbsolutePage = iPageCurrent<br /><br /> ' Show a quick status line letting people know where they are:<br /> %><br /> <p align="right"><br /> <%= iRecordCount %><font face="Arial" size="2"> Room(s) Found.<br /> Page <%= iPageCurrent %><br /> of <%= iPageCount %>: </font><br /> </p><br /> <%<br /> ' Display a table of the data in the recordset. We loop through the<br /> ' recordset displaying the fields from the table and using MoveNext<br /> ' to increment to the next record. We stop when we reach EOF.<br /> ' For fun I'm combining some fields and showwing you can do more then<br /> ' just spit out the data in the form it is in in the table.<br /> %><br /> <table border="0"><br /> <tr bgcolor="#fffoe8"><br /> <th><font face="Arial" size="2">Room Category</font></th><br /> <th><font face="Arial" size="2">Ref.</font></th><br /> <th><font face="Arial" size="2">Date Room Added</font></th><br /> <th><font face="Arial" size="2">County</font></th><br /> <th><font face="Arial" size="2">London Zone</font></th><br /> <th><font face="Arial" size="2">Location</font></th><br /> <th><font face="Arial" size="2">Weekly Rent</font></th><br /> <th><font face="Arial" size="2">Male or Female Wanted</font></th><br /> <th><font face="Arial" size="2">Map</font></th><br /> <th><font face="Arial" size="2">Preferred Contact Method</font></th><br /> <th><font face="Arial" size="2">Mobile</font></th><br /> <th><font face="Arial" size="2">Telephone</font></th><br /> <th><font face="Arial" size="2">Email</font></th><br /> </tr><br /> <%<br /> rowcount=0<br /> Do While Not rstSearch.EOF And rstSearch.AbsolutePage = iPageCurrent<br /> if rowcount mod 2 then <br /> bgcolor = "FFF0E8"<br /> else<br /> bgcolor = "ECFFEC"<br /> end if<br /> %><br /> <tr bgcolor="#<%=bgcolor%>"> <br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("category2").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("id").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("addeddate").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("county").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("londonzone").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("location").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("weeklyrent").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("gender").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("map").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("preferredcontactmethod").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("mobile").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("telephone").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("email").Value %>*</td><br /> </tr><br /> <%<b /> rowcount=rowcount+1<br /> rstSearch.MoveNext<br /> Loop<br /><br /> %><br /> </table><br /> <p align="center"><br /> <%<br /> ' Now we need to show our navigation links:<br /> <br /> ' Show "previous" and "next" page links which pass the page to<br /> ' view our search parameter. You could also use form buttons<br /> ' but I find this looks better.<br /> If iPageCurrent > 1 Then<br /> %> <font face="Arial" size="2"><br /> <a href="<%= strURL %>?county=<%= Server.URLEncode(county) %>&londonzone=<%= Server.URLEncode(londonzone) %>&weeklyrent=<%= Server.URLEncode(weeklyrent) %>&searchoptions=<%= Server.URLEncode(searchoptions) %>&page=<%= iPageCurrent - 1 %>">[<< Prev]</a><br /> <%<br /> End If<br /><br /> ' You can also show page numbers:<br /> For I = 1 To iPageCount<br /> If I = iPageCurrent Then<br /> %><br /> <%= I %><br /> <%<br /> Else<br /> %><br /> <a href="<%= strURL %>?county=<%= Server.URLEncode(county) %>&londonzone=<%= Server.URLEncode(londonzone) %>&weeklyrent=<%= Server.URLEncode(weeklyrent) %>&searchoptions=<%= Server.URLEncode(searchoptions) %>&page=<%= I %>"><%= I %></a><br /> <%<br /> End If<br /> Next 'I<br /><br /> If iPageCurrent < iPageCount Then<br /> %><br /> <a href="<%= strURL %>?county=<%= Server.URLEncode(county) %>&londonzone=<%= Server.URLEncode(londonzone) %>&weeklyrent=<%= Server.URLEncode(weeklyrent) %>&searchoptions=<%= Server.URLEncode(searchoptions) %>&page=<%= iPageCurrent + 1 %>">[Next >>]</a><br /> <%<br /> End If<br /> %> </font><br /> </p><br /><p align="center"><font face="Arial" size="2"><br /><a target="_top" href="addaroom.asp">Add a Room</a> - <br /><a target="_top" href="affiliate.asp">Our Rooms on Your <br />Site (Affiliate)</a> - Room Hosting - Free Email - Free Webspace</font></p><br /><p align="center"><font size="1" face="Arial">?2002 Cyber Ethos Limited</font></p><br /><br /><p align="center">*</p><br /><br /> </font><br /><br /> <%<br /> End If<br /><br /> ' Close our recordset and connection and dispose of the objects<br /> rstSearch.Close<br /> Set rstSearch = Nothing<br /> cnnSearch.Close<br /> Set cnnSearch = Nothing<br />End If<br />%><br /><br /><br /><br />

Was this answer helpful ? Yes No   
Guest


<i><b>Originally posted by : Lee Farrant (leefarrant@hotmail.com)</b></i><br />Hello Zeeshan,<br />Thank you for taking the time out to reply to my rather long message. I placed your suggestion here <br /><br /> rstSearch.Cursor=adUseClient<br /><br /> ' Open our recordset<br /> rstSearch.Open strSQL, cnnSearch, adOpenStatic, adLockReadOnly, adCmdText<br /><br />but I get an error <br /><br />Error Type:<br />Microsoft VBScript runtime (0x800A01B6)<br />Object doesn't support this property or method: 'Cursor'<br /><br />Have a placed it incorrectly?<br /><br />Lee<br /><br /><br />------------<br />Zeeshan Ahmad at 4/2/2002 12:14:50 AM<br /><br />Use this line between creating recordset object and open recordset object<br /><br />"Rs.Cursor=adUserClient"<br /><br /><br />------------<br />Lee Farrant at 3/30/2002 1:29:07 PM<br /><br />below is some sample code which I have added to. <br /><br />Since I changed from a dsnless to a DSN connection I am having some problems. the count of records get displayed in my webpages fine so the RecordCount works so the SQL must be running, but it will not display the records in a table. It does not error. Just displays the table header cells.<br /><br />Can anyone see what I have done wrong.<br /><br />Thanks<br />Lee<br /> <br /><br /><%<br />' Constants ripped from adovbs.inc:<br /> Const adOpenStatic = 3<br /> Const adLockReadOnly = 1<br /> Const adCmdText = &H0001<br /><br />' Our own constants:<br />Const PAGE_SIZE = 5 ' The size of our pages.<br /><br />' Declare our variables... always good practice!<br />Dim strURL ' The URL of this page so the form will work<br /> ' no matter what this file is named.<br /><br />Dim cnnSearch ' ADO connection<br />Dim rstSearch ' ADO recordset<br />Dim strDBPath ' path to our Access database (*.mdb) file<br /><br />Dim strSQL ' The SQL Query we build on the fly<br />Dim ukstrSQL<br />Dim londonstrSQL<br />Dim strSearch ' The text being looked for<br /><br />Dim iPageCurrent ' The page we're currently on<br />Dim iPageCount ' Number of pages of records<br />Dim iRecordCount ' Count of the records returned<br />Dim I ' Standard looping variable<br /><br />Dim county<br />Dim londonzone<br />Dim weeklyrent<br /><br />strURL = Request.ServerVariables("URL")<br /><br />county = Request.QueryString("county")<br />londonzone = Request.Querystring("londonzone")<br />weeklyrent = Request.Querystring("weeklyrent")<br />gocheck = Request.Querystring("county") + Request.Querystring("londonzone")<br />searchoptions = Request.QueryString("searchoptions")<br /><br />' Retrieve page to show or default to the first<br />If Request.QueryString("page") = "" Then<br /> iPageCurrent = 1<br />Else<br /> iPageCurrent = CInt(Request.QueryString("page"))<br />End If<br /><br />' Since I'm doing this all in one page I need to see if anyone<br />' has searched for something. If they have we hit the DB.<br />' O/W I just show the search form and quit.<br />%><br /><form action="<%= strURL %>" method="get" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1"><br /><p align="right"><br /><img border="0" src="../images/signin.gif"><a target="_top" href="http://www.blabla.com/"><img border="0" src="../images/Room_Logo_trans.gif" align="left"></a> <br><br />*</p><br /><p align="left"><br /><br><br /><!--webbot bot="Validation" s-display-name="UK County" b-value-required=""TRUE"" --><select size="1" name="county"><br /> <br /><option selected value="none">UK County</option><br /><option value="Avon">England Avon</option><br /><option value="Bedfordshire">England Bedfordshire</option><br /><option value="Berkshire">England Berkshire</option><br /><option value="Buckinghamshire">England Buckinghamshire</option><br /><option value="Cambridgeshire">England Cambridgeshire</option><br /><option value="Cheshire">England Cheshire</option><br /><option value="Cleveland">England Cleveland</option><br /><option value="Cornwall">England Cornwall</option><br /><option value="Cumbria">England Cumbria</option><br /><option value="Derbyshire">England Derbyshire</option><br /><option value="Devon">England Devon</option><br /><option value="Dorset">England Dorset</option><br /><option value="Durham">England Durham</option><br /><option value="East Sussex">England East Sussex</option><br /><option value="Essex">England Essex</option><br /><option value="Gloucestershire">England Gloucestershire</option><br /><option value="Greater Manchester">England Greater Manchester</option><br /><option value="Hampshire">England Hampshire</option><br /><option value="Herefordshire">England Herefordshire</option><br /><option value="Humberside">England Humberside</option><br /><option value="Isle of Wight">England Isle of Wight</option><br /><option value="Isle of Scilly">England Isle of Scilly</option><br /><option value="Kent">England Kent</option><br /><option value="Lancashire">England Lancashire</option><br /><option value="Leicestershire">England Leicestershire</option><br /><option value="Lincolnshire">England Lincolnshire</option><br /><option value="Merseyside">England Merseyside</option><br /><option value="Norfolk">England Norfolk</option><br /><option value="North Yorkshire">England North Yorkshire</option><br /><option value="Northamptonshire">England Northamptonshire</option><br /><option value="Northumberland">England Northumberland</option><br /><option value="Nottinghamshire">England Nottinghamshire<br /><option value="Oxfordshire">England Oxfordshire</option><br /><option value="Rutland">England Rutland</option><br /><option value="Shropshire">England Shropshire</option><br /><option value="Somerset">England Somerset</option><br /><option value="South Yorkshire">England South Yorkshire</option><br /><option value="Staffordshire">England Staffordshire</option><br /><option value="Suffolk">England Suffolk</option><br /><option value="Surrey">England Surrey</option><br /><option value="Tyne and Wear">England Tyne and Wear</option><br /><option value="Warwickshire">England Warwickshire</option><br /><option value="West Midlands">England West Midlands</option><br /><option value="West Sussex">England West Sussex</option><br /><option value="West Yorkshire">England West Yorkshire</option><br /><option value="Wiltshire">England Wiltshire</option><br /><option value="Worcestershire">England Worcestershire</option><br /><option value="Clwyd">Wales Clwyd</option><br /><option value="Dyfed">Wales Dyfed</option><br /><option value="Gwent">Wales Gwent</option><br /><option value="Gwynedd County">Wales Gwynedd County</option><br /><option value="Mid Glamorgan">Wales Mid Glamorgan</option><br /><option value="Powys">Wales Powys</option><br /><option value="South Glamorgan">Wales South Glamorgan</option><br /><option value="West Glamorgan">Wales West Glamorgan</option><br /><option value="Borders">Scotland Borders</option><br /><option value="Central">Scotland Central</option><br /><option value="Dumfries and Galloway">Scotland Dumfries and Galloway</option><br /><option value="Fife">Scotland Fife</option><br /><option value="Grampian">Scotland Grampian</option><br /><option value="Highlands and Islands">Scotland Highlands and Islands</option><br /><option value="Lothian">Scotland Lothian</option><br /><option value="Strathclyde">Scotland Strathclyde</option><br /><option value="Tayside">Scotland Tayside</option><br /><option value="County Antrim">Northern Ireland County Antrim</option><br /><option value="County Armagh">Northern Ireland County Armagh</option><br /><option value="County Down">Northern Ireland County Down</option><br /><option value="County Fermanagh">Northern Ireland County Fermanagh</option><br /><option value="County Londonderry">Northern Ireland County Londonderry</option><br /><option value="County Tyrone">Northern Ireland County Tyrone</option><br /> <br /> <br /> </select>* <font face="Arial" size="2">or</font><br /> <select size="1" name="londonzone"><br /> <option selected value="none">London Zone</option><br /> <option>1</option><br /> <option>2</option><br /> <option>3</option><br /> <option>4</option><br /> <option>5</option><br /> <option>6</option><br /> </select> <font size="2" face="Arial">and</font><br /><!--webbot bot="Validation" s-display-name="Max. Weekly Rent" b-value-required=""TRUE"" b-disallow-first-item=""TRUE"" --><select size="1" name="weeklyrent"><br /><option selected>Max. Weekly Rent</option><br /><option>40</option><br /><option>50</option><br /><option>60</option><br /><option>70</option><br /><option>80</option><br /><option>90</option><br /><option>100</option><br /><option>110</option><br /><option>120</option><br /><option>130</option><br /><option>140</option><br /><option>150</option><br /><option>160</option><br /><option>170</option><br /><option>180</option><br /><option>190</option><br /><option>200</option><br /><option>210</option><br /><option>220</option><br /><option>230</option><br /><option>240</option><br /><option>250</option><br /><option>260</option><br /></select><font size="2" face="Arial"><br><br />Search:<br /> <input type="radio" value="all" checked name="searchoptions"> All<br /> <input type="radio" name="searchoptions" value="professionals">Professionals<br /> <input type="radio" name="searchoptions" value="students"> Students*<br /> <input type="radio" name="searchoptions" value="lg"> lg<br><br /></font>*<input type="submit" value="Search" name="submit" /><br /><input type="reset" value="Reset" name="B1"></p><br /><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="903"><br /> <tr><br /> <td width="901" colspan="3"><br /> <p align="left">*<hr color="#FF9900" size="1"><br /> </td><br /> </tr><br /> <tr><br /> <td width="113"><br /> <b><font face="Arial" size="2"><br /> <a target="_top" href="http://www.blabla.com/professionals/"><br /> Professionals</a>* </font></b></td><br /> <td width="110"><br /> <b><font face="Arial" size="2">**<br /> <a target="_top" href="http://www.blabla.com/students/">Students</a></font></b></td><br /> <td width="680"><br /> <font face="Arial" size="2"><br /> <b><br /> <a target="_top" href="http://www.blabla.com/lg/">lg</a> </b><br /> (Professionals & Students)</font></td><br /> </tr><br /></table><br /></form><br />*<%<br /><br />If gocheck <> "nonenone" Then<br /> ' MapPath of virtual database file path to a physical path.<br /> ' If you want you could hard code a physical path here.<br /> ' strDBPath = Server.MapPath("test.mdb")<br /><br /><br /> ' Create an ADO Connection to connect to the sample database.<br /> ' We're using OLE DB but you could just as easily use ODBC or a DSN.<br /> Set cnnSearch = Server.CreateObject("ADODB.Connection")<br /> cnnSearch.open "DSN=profiles"<br /> <br /> ' This line is for the Access sample database:<br /> ' cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"<br /><br /> ' We're actually using SQL Server so we use this line instead:<br /> ' cnnSearch.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _<br /> ' & "Initial Catalog=samples;User Id=samples;Password=password;" _<br /> ' & "Connect Timeout=15;Network Library=dbmssocn;"<br /> <br /> dim searchcat<br /> select case searchoptions<br /> case "all"<br /> searchcat = ""<br /> case "professionals"<br /> searchcat = " and category2 = 'professionals'"<br /> case "students"<br /> searchcat = " and category2 = 'students'"<br /> case "lg"<br /> searchcat = " and category2 = 'lg'"<br /> end select<br /> <br /> dim searchareacat<br /> searchareacat = " county =" & "'" & county & "'" & " and category = 'uk'"<br /> <br /> select case county <br /> case "none"<br /> searchareacat = " londonzone = " & londonzone & " and category = 'london'"<br /> end select<br /> <br /> ' strSQL = "SELECT * " & "FROM roomprofiles " & "where londonzone = " & londonzone & " and weeklyrent <=" & weeklyrent & searchcat<br /> <br /> strSQL = "SELECT category2,id,addeddate,county,londonzone,location, weeklyrent,gender,map,preferredcontactmethod,mobil e,telephone,email " & "FROM roomprofiles " _<br /> & "where " & searchareacat & " and weeklyrent <=" & weeklyrent & searchcat & " and date() <= expireDate"<br /> <br /> ' Execute our query using the connection object. It automatically<br /> ' creates and returns a recordset which we store in our variable.<br /> <br /> Set rstSearch = Server.CreateObject("ADODB.Recordset")<br /> rstSearch.ActiveConnection = cnnSearch<br /> <br /> rstSearch.PageSize = PAGE_SIZE<br /> rstSearch.CacheSize = PAGE_SIZE<br /><br /> ' Open our recordset<br /> rstSearch.Open strSQL, cnnSearch, adOpenStatic, adLockReadOnly, adCmdText<br /><br /> ' Get a count of the number of records and pages<br /> ' for use in building the header and footer text.<br /> iRecordCount = rstSearch.RecordCount<br /> iPageCount = rstSearch.PageCount<br /> If iRecordCount = 0 Then<br /> ' Display no records error.<br /> %><br /> <p align="center"><br /> <b><br /> <font size="2" face="Arial">Sorry no rooms match your requirement at the <br /> moment. See our overview of <br /> available <a target="_top" href="londonsummary.asp">London</a> or <br /> <a target="_top" href="uksummary.asp">UK</a> rooms. </font><br /> <br /> </b><br /> <br /> </p><br /><p align="center"><font face="Arial" size="2"><br /><a target="_top" href="addaroom.asp">Add a Room</a> -<br /><a target="_top" href="affiliate.asp">Our Rooms on Your Site (Affiliate)</a> - <br />Room Hosting - Free Email - Free Webspace</font></p><br /><p align="center"><font size="1" face="Arial">?2002 Cyber Ethos Limited</font></p><br /><br /> <p align="center"><br /> *</p><br /> <%<br /> Else<br /> Response.Write(strSQL)<br /> ' Move to the page we need to show. <br /> rstSearch.AbsolutePage = iPageCurrent<br /><br /> ' Show a quick status line letting people know where they are:<br /> %><br /> <p align="right"><br /> <%= iRecordCount %><font face="Arial" size="2"> Room(s) Found.<br /> Page <%= iPageCurrent %><br /> of <%= iPageCount %>: </font><br /> </p><br /> <%<br /> ' Display a table of the data in the recordset. We loop through the<br /> ' recordset displaying the fields from the table and using MoveNext<br /> ' to increment to the next record. We stop when we reach EOF.<br /> ' For fun I'm combining some fields and showwing you can do more then<br /> ' just spit out the data in the form it is in in the table.<br /> %><br /> <table border="0"><br /> <tr bgcolor="#fffoe8"><br /> <th><font face="Arial" size="2">Room Category</font></th><br /> <th><font face="Arial" size="2">Ref.</font></th><br /> <th><font face="Arial" size="2">Date Room Added</font></th><br /> <th><font face="Arial" size="2">County</font></th><br /> <th><font face="Arial" size="2">London Zone</font></th><br /> <th><font face="Arial" size="2">Location</font></th><br /> <th><font face="Arial" size="2">Weekly Rent</font></th><br /> <th><font face="Arial" size="2">Male or Female Wanted</font></th><br /> <th><font face="Arial" size="2">Map</font></th><br /> <th><font face="Arial" size="2">Preferred Contact Method</font></th><br /> <th><font face="Arial" size="2">Mobile</font></th><br /> <th><font face="Arial" size="2">Telephone</font></th><br /> <th><font face="Arial" size="2">Email</font></th><br /> </tr><br /> <%<br /> rowcount=0<br /> Do While Not rstSearch.EOF And rstSearch.AbsolutePage = iPageCurrent<br /> if rowcount mod 2 then <br /> bgcolor = "FFF0E8"<br /> else<br /> bgcolor = "ECFFEC"<br /> end if<br /> %><br /> <tr bgcolor="#<%=bgcolor%>"> <br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("category2").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("id").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("addeddate").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("county").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("londonzone").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("location").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fi lds("weeklyrent").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("gender").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("map").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("preferredcontactmethod").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("mobile").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("telephone").Value %>*</td><br /> <td><font face="Arial" size="2"><%= rstSearch.Fields("email").Value %>*</td><br /> </tr><br /> <%<br /> rowcount=rowcount+1<br /> rstSearch.MoveNext<br /> Loop<br /><br /> %><br /> </table><br /> <p align="center"><br /> <%<br /> ' Now we need to show our navigation links:<br /> <br /> ' Show "previous" and "next" page links which pass the page to<br /> ' view our search parameter. You could also use form buttons<br /> ' but I find this looks better.<br /> If iPageCurrent > 1 Then<br /> %> <font face="Arial" size="2"><br /> <a href="<%= strURL %>?county=<%= Server.URLEncode(county) %>&londonzone=<%= Server.URLEncode(londonzone) %>&weeklyrent=<%= Server.URLEncode(weeklyrent) %>&searchoptions=<%= Server.URLEncode(searchoptions) %>&page=<%= iPageCurrent - 1 %>">[<< Prev]</a><br /> <%<br /> End If<br /><br /> ' You can also show page numbers:<br /> For I = 1 To iPageCount<br /> If I = iPageCurrent Then<br /> %><br /> <%= I %><br /> <%<br /> Else<br /> %><br /> <a href="<%= strURL %>?county=<%= Server.URLEncode(county) %>&londonzone=<%= Server.URLEncode(londonzone) %>&weeklyrent=<%= Server.URLEncode(weeklyrent) %>&searchoptions=<%= Server.URLEncode(searchoptions) %>&page=<%= I %>"><%= I %></a><br /> <%<br /> End If<br /> Next 'I<br /><br /> If iPageCurrent < iPageCount Then<br /> %><br /> <a href="<%= strURL %>?county=<%= Server.URLEncode(county) %>&londonzone=<%= Server.URLEncode(londonzone) %>&weeklyrent=<%= Server.URLEncode(weeklyrent) %>&searchoptions=<%= Server.URLEncode(searchoptions) %>&page=<%= iPageCurrent + 1 %>">[Next >>]</a><br /> <%<br /> End If<br /> %> </font><br /> </p><br /><p align="center"><font face="Arial" size="2"><br /><a target="_top" href="addaroom.asp">Add a Room</a> - <br /><a target="_top" href="affiliate.asp">Our Rooms on Your <br />Site (Affiliate)</a> - Room Hosting - Free Email - Free Webspace</font></p><br /><p align="center"><font size="1" face="Arial">?2002 Cyber Ethos Limited</font></p><br /><br /><p align="center">*</p><br /><br /> </font><br /><br /> <%<br /> End If<br /><br /> ' Close our recordset and connection and dispose of the objects<br /> rstSearch.Close<br /> Set rstSearch = Nothing<br /> cnnSearch.Close<br /> Set cnnSearch = Nothing<br />End If<br />%><br /><br /><br /><br />

Was this answer helpful ? Yes No   
Guest


rstSearch.Cursor=adUseClient -- this line is not needed . Just comment this line





Rest is fine

' Open our recordset

rstSearch.Open strSQL, cnnSearch, adOpenStatic, adLockReadOnly, adCmdText



I would suggest u to study throughly the ADO prgramming where you can get a good idea about recordset

Was this answer helpful ? Yes No   
Guest


Jump to the last record (rs.MoveLast) then rs.RecordCount contains the number of records. Don't forget to jump back to the beginning if you want to loop thru your records afterwards.

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved