ADO Samples

ActiveCommand Property Example (JScript)

This example demonstrates the ActiveCommand property.

<!-- BeginActiveCommandJS -->
<% @LANGUAGE="JScript" %>
<%
   Response.Write(Request.Form("ContactName"));
   
   strName = new String(Request.Form("ContactName"))
%>

<html>

<head>
<title>ActiveCommand Property Example (JScript)</title>
<style>
<!--
BODY {
   font-family: 'Verdana','Arial','Helvetica',sans-serif;
   BACKGROUND-COLOR:white;
   COLOR:black;
    }
-->
</style>
</head>

<body bgcolor="White">

<h1>ActiveCommand Property Example (JScript)</h1>

<%
   if (strName.length > 0)
   {
      // Open the connection.
      var Connect = "Provider=sqloledb;Data Source=" +
                    Request.ServerVariables("SERVER_NAME") + ";" +
                    "Initial Catalog=Northwind;User Id=sa;Password=;"
   
      // Open a recordset on the Customers table using
      // a command object.
      var cnn = Server.CreateObject("ADODB.Connection");
      var cmdContact = Server.CreateObject("ADODB.Command");
      var rsContact = Server.CreateObject("ADODB.Recordset");
   
      cnn.Open(Connect);
   
      cmdContact.CommandText = "SELECT * FROM Customers WHERE ContactName = ?";
      cmdContact.Parameters.Append(cmdContact.CreateParameter("ContactName", adChar, adParamInput, 30, strName));
      cmdContact.ActiveConnection = cnn;
      
      rsContact = cmdContact.Execute();
   
      var strMessage;      // used to build up line before writing to document.

      while (!rsContact.EOF)
      {
         // Start a new line.
         strMessage = "<P>";
            
         // First and last name are in first column.
         strMessage += rsContact.Fields("ContactName")
            
         // End the line.
         strMessage += "</P>";
         
         // Write line to document.
         Response.Write(strMessage);
            
         // Get next record.
         rsContact.MoveNext;

      }
   
      // Close table.
      rsContact.Close;
   }
%>

<hr>


<form method="POST" action="ActiveCommandJS.asp">
  <p align="left">Enter last name of author to find (e.g., Ringer): <input type="text" name="ContactName" size="40" value=""></p>
  <p align="left"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>

</html>
<!-- EndActiveCommandJS -->

See Also

ActiveCommand Property | Command Object | Recordset Object