Model for the CNPS Manual of California Vegetation Web site

Active Server Pages/VB Script sample reference using ADO (ActiveX Data Objects)


<% ... %>

- All code/script in between angle brackets and percent signs is interpreted/evaluated by the server which generates and returns to the client browser an HTML page. The client browser never sees the ASP script.

Request.Form("xxx")

- The Request form object is the form submission from the browser client to the Web server. The submitted data is processed by the server.

  <FORM METHOD=POST ACTION="SeriesSearch.asp">
  <SELECT NAME="seriesOption" SIZE=1>
  <option value= "iseq">Equal to </option>
  <option value= "isnt">Not Equal to </option>
  <option selected value= "swth">Begins With </option>
  <option value= "ewth">Ends With </option>
  <option value="cont">Contains</option></SELECT>
  <INPUT NAME="seriesName" TYPE=TEXT SIZE=30 MAXLENGTH=30>

In the preceding example, the seriesOption and the seriesName parameters are sent to the server and processed by the SeiresSearch.asp, which has the Request.Form("seriesOption") and Request.Form("seriesName") script as part of the ASP file.

Request.QueryString("xxx")

- The Request querystring object is a hyperlink method using an anchored (<A>) hypertext reference (<A HREF>) to designate a target page and carry data to the taget page.

  <A HREF="http://davisherb.ucdavis.edu/SeriesDetail.asp?seriesName=Alaska+yellow%2Dcedar+stands">A series</A>

In the above example, the anchored hypertext reference will carry data (seriesName=Alaska+yellow%2Dcedar+stands) to the target page (SeriesDetail.asp) to be processed by the server which has the Request.QueryString("seriesName") script as part of the ASP file.

Response.Write("xxx") or ="xxx"

- The Response write object is the HTML text returned to the client browser by the server.

  <%Response.Write "seriesName"%>

In the preceding example, the server returns the value for the variable seriesName to the client browser.

Server.CreateObject("ADODB.xxx")

- The ASP Server has server component objects you can create by using the CreateObject method; Once created, you can access its properties and methods to perform functions like database queries. The object ADODB.Connection establishes a database connection object.

  <%
  ' Declare a database connection variable
  DIM objConnection
  ' Create a connection object
  Set objConnection = Server.CreateObject("ADODB.Connection")
  ' Open the data source connection
  objConnection.Open "CalVeg"
  ' Declare a recordset variable
  DIM objRecordset
  ' Create the Recordset object
  Set objRecordset = Server.CreateObject("ADODB.Recordset")
  ' Run SQL query on recordset on the data object objConnection
  objRecordset.Open "SELECT SeriesName", objConnection
  ' Loop through recordset displaying data until end of file
  Do While Not objRecordset.EOF
  Response.Write "seriesName"
  objRecordset.MoveNext
  Loop
  %>

In the preceding example, DIM objConnection declares the variable used as an object reference to the instance of the Connection object. The objConnection.Open method establishes the data source connection, in this case to the OBDC (Object Database Connectivity) datasource defined as CalVeg stored on the server. The recordset is similarily declared with DIM objRecordset and objRecordset.Open. Using ASP Visual Basic script statements then allows looping through the entire recordset displaying the seriesName field data.


A Sample CNPS California Vegetation Web Page residing on the server (client browser will see the server side generated HTML, not the ASP script):

<%@ LANGUAGE="VBSCRIPT"%>

<%Response.Expires=0%>

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="GENERATOR" content="Microsoft FrontPage 2.0">

<title>California Vegetation species - latin name</title>

</head>

<body bgcolor="#FFFFFF" link="#0000FF" vlink="#800080">

<ul><li>

<li><p align="right"><a href="index.html"><img src="vegcnps.gif"

alt="CNPS - Vegetation of California" align="center" border="0" width="230" height="101"></a>

<img src="vrule.gif" align="absbottom" width="1" height="100">

<a href="http://www.calpoly.edu/~dchippin/cnps_main.html"><font size="4">

California Native Plant Society</font></a></p>

</li></ul>

<hr>

<%

DIM latinname

latinname = Request.QueryString("detail")

Set DataConn = Server.CreateObject("ADODB.Connection")

DataConn.Open "CNPSICE"

Set DataCmd = Server.CreateObject("ADODB.Command")

SQLstr = "SELECT DISTINCTROW CLATMAST.SPCNAME, CLATMAST.LATNAME, [3SERIES].SERNAME, "

SQLstr = SQLstr & "[3SERIES].[3SERIESID], CLATMAST.CLATMASTID, [3SERSPC].[3SERSPCID], "

SQLstr = SQLstr & "[3SERIES].SECTIONNAME, SpeciesHyperlnks.CLATMASTID AS TheLink, "

SQLstr = SQLstr & "[3SERIES].Formation FROM ((3SERSPC INNER JOIN CLATMAST ON "

SQLstr = SQLstr & "[3SERSPC].PLANTCODE = CLATMAST.PLANTCODE) INNER JOIN 3SERIES ON "

SQLstr = SQLstr & "[3SERSPC].SERCODE = [3SERIES].SERCODE) LEFT JOIN SpeciesHyperlnks ON "

SQLstr = SQLstr & "CLATMAST.CLATMASTID = SpeciesHyperlnks.CLATMASTID "

SQLstr = SQLstr & "WHERE CLATMAST.LATNAME = '" & latinname & "'"

DataCmd.CommandText = SQLstr

Set DataCmd.ActiveConnection = DataConn

Set rs_CNPS = Server.CreateObject("ADODB.Recordset")

Set rs_CNPS = DataCmd.execute

%>

<table border="0">

<tr>

<td><font size="4"><strong>Species Details for: </strong></font>Latin

Name: <i><% =rs_CNPS("LATNAME") %></i> &nbsp; (Common Name: <% =rs_CNPS("SPCNAME")%>) </td>

</tr>

<tr>

<td>&nbsp;</td>

</tr>

<tr>

<td><table border="2">

<tr>

<td bgcolor="#C0C0C0"><em>[Select from below list

for more details from associated Web sites]</em></td>

</tr>

<tr><td><ul>

<li><a

href="http://elib.cs.berkeley.edu/cgi-bin/illus_query?table=flowers&amp;like-char-latin_name=<% =Server.URLEncode(rs_CNPS("LATNAME"))%>">Brousseau

California Flora (Images), part of the

electronic library at University of

California at Berkeley</a> </li>

<li><a

href="http://nardac.mip.berkeley.edu/cgi-bin/browse_smasch_checklist?taxon_common_name=<% =Server.URLEncode(rs_CNPS("LATNAME"))%>&amp;next_action=specimens">SMASCH

herbarium specimen details, University of

California at Berkeley</a> </li>

<li><a

href="http://elib.cs.berkeley.edu/cgi-bin/illus_query?table=calflora&amp;eq-char-taxon_name=<% =Server.URLEncode(rs_CNPS("LATNAME"))%>&amp;next_action=specimens">California

Flora Database species detail, University

of California at Berkeley</a> </li>

</ul></td></tr></table>

</td></tr></table>

<%

dim x

x = 0

While not rs_CNPS.EOF

x = x + 1

rs_CNPS.MoveNext

wend

rs_CNPS.MoveFirst

%>

<p><b>Vegetation Series of occurrence (there are <% =x %>):</b> </p>

<table border="0" cellspacing="0">

<%

While not rs_CNPS.eof %> <tr>

<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a

href="SeriesDetail.asp?seriesname=<%=Server.URLEncode(rs_CNPS("SERNAME"))%>"><%=rs_CNPS("SERNAME")%></a></td>

<td>&nbsp;&nbsp; - <% = rs_CNPS("SECTIONNAME")%></td>

</tr>

<%

rs_CNPS.MoveNext

wend

%>

</table>

<hr>

<p>Query California Vegetation Database by: </p>

<form action="selectquery.asp" method="post">

<p><select name="selected" size="1">

<option>geography </option>

<option>sections </option>

<option>series </option>

<option>species latin name </option>

<option>species common name </option>

</select> <input type="submit" value=" Select and Continue ">

</p>

</form>

<p align="right"><a href="index.html">home</a> | <a

href="links.html">links</a> | <a href="terms.html">terms</a> </p>

<p>&nbsp;</p>

<p><font size="2"><i> CNPS 1997</i></font> </p>

</body>

</html>


CNPS Manual of California Vegetation Web Site | Database structure