Can i use 3 recordsets?

Author Message
mdlister

  • Total Posts : 88
  • Scores: 0
  • Reward points : 0
  • Joined: 7/22/2008
  • Status: offline
Can i use 3 recordsets? Sunday, September 06, 2009 10:47 PM (permalink)
0
Morning,
 
I am looking at creating a page that displays events in date order but i wanted to have them listed in 3 tables and have thought about this for a while and came up with a script that i thought would work but it seems that only the first RS works and the other 2 return all records instead of just the months. I am trying to make the site work off SQL database and make it as automated as possible.
 
I'm using Dreamwaver CS4 and hard coding bits from my VB and SQL knowledge that the program can't. here's what i have at the moment, any suggestions on fixing this or better ways? I thought about one RS and maybe passing it to an array or something?
 
not looking for someone to do the work for me but help with either snippets or alternative methods would be greatful
 
Events.asp
      <%@LANGUAGE="VBSCRIPT"%>
     <!--#include file="Connections/ConnDatabase.asp" -->
     <!--#include file="includes/session.asp" -->     <%
     Dim RSEvents__MMColParam
     Dim Months
     RSEvents__MMColParam = Session("ShortMonth")
     Month2 = MonthName(Session("intMonth")+1)
     Month3 = MonthName(Session("intMonth")+2)
     'RSEvents__MMColParam2 = Left(Month2,3)
     'RSEvents__MMColParam3 = Left(Month3,3)     %>
     <!--#include file="includes/RS.asp" -->
     <!--#include file="includes/RS2.asp" -->
     <!--#include file="includes/RS3.asp" -->
     <%
     Dim Repeat1__numRows
     Dim Repeat1__index     Repeat1__numRows = -1
     Repeat1__index = 0
     RSEvents_numRows = RSEvents_numRows + Repeat1__numRows     %>
     <%
     Dim Repeat3__numRows
     Dim Repeat3__index     Repeat3__numRows = -1
     Repeat3__index = 0
     RSEvents3_numRows = RSEvents3_numRows + Repeat3__numRows
     %>
     <%
     Dim Repeat2__numRows
     Dim Repeat2__index     Repeat2__numRows = -1
     Repeat2__index = 0
     RSEvents2_numRows = RSEvents2_numRows + Repeat2__numRows
     %>
     <p>Events in <%= Session("Month") %></p>
     <table border="0">
       <tr>
         <td>StrEventTitle</td>
         <td>DteEventDate</td>
       </tr>
       <% While ((Repeat1__numRows <> 0) AND (NOT RSEvents.EOF)) %>
         <tr>
           <td><%=(RSEvents.Fields.Item("StrEventTitle").Value)%></td>
           <td><%=(RSEvents.Fields.Item("DteEventDate").Value)%></td>
         </tr>
         <% 
       Repeat1__index=Repeat1__index+1
       Repeat1__numRows=Repeat1__numRows-1
       RSEvents.MoveNext()
     Wend
     %>
     </table>
     <p>
     <p>Events in <%response.write(month2)%></p>
     <table border="0">
       <tr>
         <td>StrEventTitle</td>
         <td>DteEventDate</td>
       </tr>
     <% While ((Repeat2__numRows <> 0) AND (NOT RSEvents2.EOF)) %>
         <tr>
           <td><%=(RSEvents2.Fields.Item("StrEventTitle").Value)%></td>
           <td><%=(RSEvents2.Fields.Item("DteEventDate").Value)%></td>
         </tr>
     <% 
       Repeat2__index=Repeat2__index+1
       Repeat2__numRows=Repeat2__numRows-1
       RSEvents2.MoveNext()
     Wend
     %>
     </table>
     <p>
     <p>Events in <%response.write(month3)%></p>     <table border="0">
       <tr>
         <td>StrEventTitle</td>
         <td>DteEventDate</td>
       </tr>
       <% While ((Repeat3__numRows <> 0) AND (NOT RSEvents3.EOF)) %>
         <tr>
           <td><%=(RSEvents3.Fields.Item("StrEventTitle").Value)%></td>
           <td><%=(RSEvents3.Fields.Item("DteEventDate").Value)%></td>
         </tr>
     <% 
       Repeat3__index=Repeat3__index+1
       Repeat3__numRows=Repeat3__numRows-1
       RSEvents3.MoveNext()
     Wend
     %>
     </table>
     <p>
       <!--#include file="includes/CloseRS.asp" -->     

 
session.asp
       <% Session("intMonth")=Month(now) 
     Session("Month")=MonthName(Session("intMonth"))
     Session("ShortMonth") = Left(Session("Month"),3)     Month2 = MonthName(Session("intMonth")+1)
     Month3 = MonthName(Session("intMonth")+2)
     RSEvents__MMColParam2 = Left(Month2,3)
     RSEvents__MMColParam3 = Left(Month3,3)
     %>     

 
RS.asp
       <%
     Dim RSEvents
     Dim RSEvents_cmd
     Dim RSEvents_numRows     Set RSEvents_cmd = Server.CreateObject ("ADODB.Command")
     RSEvents_cmd.ActiveConnection = MM_ConnDatabase_STRING
     RSEvents_cmd.CommandText = "SELECT StrEventTitle, DteEventDate FROM dbo.tblEvents WHERE DteEventDate LIKE '%" + Replace(RSEvents__MMColParam, "'","''") + "%'" + " ORDER BY DteEventDate ASC"      Set RSEvents = RSEvents_cmd.Execute
     RSEvents_numRows = 0
     %>     

 
RS2.asp
       <%
     Dim RSEvents2
     Dim RSEvents2_cmd
     Dim RSEvents2_numRows     Set RSEvents2_cmd = Server.CreateObject ("ADODB.Command")
     RSEvents2_cmd.ActiveConnection = MM_ConnDatabase_STRING
     RSEvents2_cmd.CommandText = "SELECT StrEventTitle, DteEventDate FROM dbo.tblEvents WHERE DteEventDate LIKE '%" + Replace(RSEvents2__MMColParam, "'","''") + "%'" + " ORDER BY DteEventDate ASC"      Set RSEvents2 = RSEvents2_cmd.Execute
     RSEvents3_numRows = 0
     %>     

 
RS3 is the same as 2 but with 3's instead of 2's
 
CloseRS.asp
         <%
     RSEvents.Close()
     Set RSEvents = Nothing
     %>
     </p>
     <%
     RSEvents2.Close()
     Set RSEvents2 = Nothing
     %>
     <%
     RSEvents3.Close()
     Set RSEvents3 = Nothing
     %>     

 
ConnDatabase.asp
       <%
     ' FileName="Connection_ado_conn_string.htm"
     ' Type="ADO" 
     ' DesigntimeType="ADO"
     ' HTTP="false"
     ' Catalog=""
     ' Schema=""
     Dim MM_ConnDatabase_STRING
     MM_ConnDatabase_STRING = "Provider=SQLOLEDB; Server=ServerName; Initial Catalog=ExtremeSports; User Id=Username; Password=Password"
     %>     

 
#1
    jsjay9

    • Total Posts : 6
    • Scores: 0
    • Reward points : 0
    • Joined: 9/10/2009
    • Status: offline
    Re:Can i use 3 recordsets? Thursday, September 10, 2009 10:58 AM (permalink)
    0
    The answer is yes.  You CAN use as many result-sets as you can keep track of.
    I prefer to keep 'like' code in groups and limit the database calls.
     
    I don't have the database, so I couldn't run this to check for silly syntax or typing mistakes - but I think it is clear enough.
    This is just another way of doing the same thing really...
     <%@LANGUAGE="VBSCRIPT"%> 
         <!--#include file="Connections/ConnDatabase.asp" --> 
         <!--#include file="includes/session.asp" --> 
         <% 
         Dim RSEvents__MMColParam 
         Dim Month, currentMonth 
         %> 
         <!--#include file="includes/RS.asp" --> 
         <% 
         currentMonth = 0 '-- this will insure that we get a table to start --' 
         RSEvents__MMColParam = Session("ShortMonth") 
         Month2 = MonthName(Session("intMonth")+1) 
         Month3 = MonthName(Session("intMonth")+2) 
         %> 
         <HTML> 
         <HEAD> 
         </HEAD> 
         <BODY> 
         <% 
         While NOT RSEvents.EOF
         Month = Month(RSEvents.Fields.Item("DteEventDate").Value) 
         '-- if we have an event in a new month, then setup a new table --' 
         IF currentMonth <> Month then 
         '-- check to see if we have an open table to close --' 
         if currentMonth > 0 then %> 
         </TBODY> 
         </TABLE> 
         <% currentMonth = Month   end if 
         
         '-- now setup a new table for the month --' 
         %> 
         <P>Events in <%= Session("Month") %></P> 
         <TABLE border=0><TBODY> 
         <TR> 
         <TD>Event</TD> 
         <TD>Date</TD> 
         </TR> 
         <% END IF %> 
         
         <TR> 
         <TD><%=(RSEvents.Fields.Item("StrEventTitle").Value)%></TD> 
         <TD><%=(RSEvents.Fields.Item("DteEventDate").Value)%></TD> 
         </TR> 
         
         <% 
         RSEvents.MoveNext() 
         Wend 
         '-- and finally, close the last table too --' 
         %> 
         </TBODY> 
         </TABLE> 
         <P> 
         <!--#include file="includes/CloseRS.asp" --> 
         </P> 
         
         </BODY> 
         </HTML> 

    <message edited by jsjay9 on Thursday, September 10, 2009 11:01 AM>
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9