.Asp Examples

The examples in this section show how to build queries with query-object properties and methods.

Example 1

This example uses VBScript code to create a query object, set query parameters and execute the query, producing a record set for iterating over results.


<% REM Create the query and record set objects. %>
<% set Query = Server.CreateObject("IXSSO.Query") %>
<% if IsObject(Query) = FALSE then %>
   The IXS SSO has not been installed correctly. Please contact the Webmaster for this site.
<% else %>
   <% iRequest = Request.ServerVariables("QUERY_STRING") %>
   <% Query.SetQueryFromURL(iRequest)
      set RS=Query.CreateRecordSet("sequential")
   %>
<% end if %>

Example 2

Next, this example gives VBScript code to iterate over the query results using ADO, and output the query results.


<TABLE CELLPADDING=5 BORDER=0>

<!-- BEGIN column header -->

<TR>
   <TD ALIGN=CENTER>
   <FONT STYLE="ARIAL NARROW" SIZE=1>Record</FONT>
   </TD>
   <TD ALIGN=CENTER >
   <FONT STYLE="ARIAL NARROW" SIZE=1>File name</FONT>
   </TD>
   <TD ALIGN=CENTER WIDTH=160 >
   <FONT STYLE="ARIAL NARROW"  SIZE=1>Path</FONT>
   </TD>
   <TD ALIGN=CENTER >
   <FONT STYLE="ARIAL NARROW" SIZE=1>Size</FONT>
   </TD>
   <TD ALIGN=CENTER >
   <FONT STYLE="ARIAL NARROW" SIZE=1>Write</FONT>
   </TD>
</TR>

<!-- BEGIN first row of query results table -->
<%NextRecordNumber = 1%>
<% Do While Not RS.EOF%>
  <TR>
   <TD ALIGN=CENTER>
   <FONT STYLE="ARIAL NARROW" SIZE=1><%=NextRecordNumber %>.</FONT></TD>
   <TD ALIGN=CENTER>
   <FONT STYLE="ARIAL NARROW" SIZE=1><%=RS("FileName")%></FONT></TD>
   <TD ALIGN=CENTER>
   <FONT STYLE="ARIAL NARROW" SIZE=1><A HREF="http::<%=RS("vpath")%>"><%=RS("vpath")%></A></FONT></TD>
   <TD ALIGN=CENTER>
   <FONT STYLE="ARIAL NARROW" SIZE=1><%=RS("Size")%></FONT></TD>
   <TD ALIGN=CENTER>
   <FONT STYLE="ARIAL NARROW" SIZE=1><%=RS("Write")%></FONT></TD>
  </TR>
<%
   RS.MoveNext
   NextRecordNumber = NextRecordNumber+1
  Loop
%>

Example 3

This example shows how the query and record set can be cached in session variables for reuse on another page:

<%
   if IsObject(Session("Query")) And IsObject(Session("record set"))
   then
      set Q = Session("Query")
      set RS = Session("record set")
      if RS.RecordCount < > -1 and NextPageNumber < > -1 then
         RS.AbsolutePage = NextPageNumber
         NextRecordNumber = RS.AbsolutePosition
      end if
      ActiveQuery = TRUE
   else
      <!-- Create new query (code omitted for brevity) -->
   end if
%>

<!-- Later on the page -->
<%
   ' If either of the previous or back buttons were displayed, save
   ' the query and the record set in session variables.
   if SaveQuery then
      set Session("Query") = Q
      set Session("record set") = RS
   else
      RS.close
      Set RS = Nothing
      Set Q = Nothing
      set Session("Query") = Nothing
      set Session("record set") = Nothing
   end if

%>

Example 4

The next example shows how the QUERY_STRING or form variables can be parsed from VBScript without requiring the SetQueryFromURL method.


<%
   NewQuery = FALSE
   UseSavedQuery = FALSE
   SearchString = ""
   if Request.ServerVariables("REQUEST_METHOD") = "POST" then
         NewQuery = TRUE
      SearchString = Request.Form("SearchString")
      SortBy = Request.Form("SortBy")
      Colset = Request.Form("ColChoice")
      Catalog = Request.Form("Catalog")
      if Request.Form("Action") = "New Query" then
      end if
   end if
   if Request.ServerVariables("REQUEST_METHOD") = "GET" then
      SearchString = Request.QueryString("qu")
      SortBy = Request.QueryString("so")
      Colset = Request.QueryString("co")
      Catalog = Request.QueryString("ct")
      if Request.QueryString("pg") <> "" then
         NextPageNumber = Request.QueryString("pg")
         NewQuery = FALSE
         UseSavedQuery = TRUE
      else
         NewQuery = SearchString <> ""
      end if
   end if
 %>

© 1997 by Microsoft Corporation. All rights reserved.