Asp/Access Php/MySql

Example of Search Response That Has Key Field As

A QueryString in a Hyperlink Tag To Send To Delete Form Request

Using VBScript, ASP, ADO and a OLEDB Connection

Prepared by Lon Hosford

 
Back to index
 

<%
'
'
'   Purpose:      Example of table search response carring table record key
'
'   Version:      1.0.0
'
'   Date:         3/4/2004
'
'   Name:         WebClubMemberDeleteSearchResponse.asp
'
'   Changes:
'      1.   Original programming
'
'   Programmer:      Lon Hosford   lon  @  hosfordusa.com
'
'
'
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
   <title>Web Masters Member Delete Search Response</title>
</head>

<body>

<%

'
'  Use the ASP Server class CreateObject action to gain access
'  to the ADODB library on the web server to
'  create a connection object from the ADODB library
'  Connection class.
'  A connection object contains all data and actions for a database
'  connection via various techniques.
'  We are using the name oConn to represent our connection object.
'

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

'
'  Use a variable to represent the connection string required
'  by the connection object. The variable is optional and
'  is a discretion to make futher lines in the code needing this
'  easier to read and maintain.
'  The connection string is made of three parts.
'      1. PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=
'      2. The server path to our Access database
'          Use the ASP Request object
'          ServerVariables("APPL_PHYSICAL_PATH")
'          to dynamically get the database path.
'      3. The name of the access database

ConnString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" 
ConnString = ConnString & Request.ServerVariables("APPL_PHYSICAL_PATH")
ConnString = ConnString  & "WebMaster.mdb"

'
'
'  Testing feedback of the ConnString variable contents.
'

Response.Write "<center>Connection String = " & ConnString & "</center>"

'
'  Use the Connection object open action to establish a connection
'  to the Access database.
'

oConn.Open ConnString

'
'  If needed uncomment next line to see any error messages
'  that might be suppressed.
'Response.Write err.number & "- " & err.description
'
'  Use a variable to represent the SQL statement.
'  The variable is optional and is a discretion to make futher
'  lines in the code needing this easier to read and maintain.
'  Select needed fields and all matching records from the table WebClubMembers

SQL =       "Select sMemberNumber, FirstName, LastName  "
SQL = SQL & "From WebClubMembers "
SQL = SQL & "Where LastName Like '"
SQL = SQL & Request.Form("lName")
SQL = SQL & "%' "
SQL = SQL & "Order By LastName, FirstName;"

'
'  Testing feedback of the SQL variable contents.
'

Response.Write "<center>SQL Statement = " & SQL & "</center>"



'
'  Use the Connection object execute action to submit the
'  SQL statement to the database and receive an ADO Recordset
'  object back with a pointer to the first record.

set oRs = oConn.Execute (SQL)

'
'
'  Create the table heading using Html.

%>

   <table border = "1" align="center">
   <tr>
      <td colspan = "3" align = "center">
      <b>Web Masters Club Delete Search Results</b>
      </td>
   </tr>

   <%
   '  Below uses a loop statement
   '  to repeat rows in the table for each record.
   '  Html and script is intermingled to make the
   '  best of use of each versus using all script
   '  ASP Response object Write actions to
   '  return the Html tags.
   '
   '  The beginning of the loop is
   '      do while not oRs.Eof
   '  The end of the loop is
   '      loop
   '  The loop repeats the lines between while
   '      the ADO RecordSet object oRS Eof value is true
   '
   '  The ADO RecordSet object moveNext action moves
   '      to next record in the record set ech loop iteration.
   '
   '  The ADO RecordSet Fields collection allows access to
   '      field object using field names in the recordset.
   '      The field objects have a value property to give
   '      the data in that field.
   '
   '
   '  After the loop the ADO RecordSet object
   '      close method is issued as standard operating
   '      procedure of good practices.
   '
   '  The first column of the table is a hyperlink that
   '      links to the edit script and sends the member record key
   '      value as a query string value. Also this is also called a Get method.
   '
   %>


   <% Do While oRs.Eof = false %>
      <tr>
         <td valign = "top">
         <%
            ' For more readable code the QueryString a variable is used
            ' to assemble the query string data.
            
            QueryString = "memNo=" & oRs.Fields("sMemberNumber").Value

         %>
            <a href = "WebClubMemberDeleteRequest.asp?<%=QueryString%>">
               View
            </a>
         </td>
         <td valign = "top">
            <%= oRs.Fields("LastName").Value & ", " %>
            <%= oRs.Fields("FirstName").Value %> 
         </td>
      </tr>
      <% oRs.MoveNext %>
   <% Loop %>
   </table>
</body>
</html>