ADO Samples

Append and CreateParameter Methods Example (JScript)

This example uses the Append and CreateParameter methods to execute a stored procedure with an input parameter.

<!-- BeginAppendJS -->
<% @LANGUAGE="JScript" %>
<!-- Include file for JScript ADO Constants -->
<!--#include File="adojavas.inc"-->

<%
   var iRoyalty = parseInt(Request.Form("RoyaltyValue"));
   
%>

<html>

<head>
   <title>Append and CreateParameter Methods Example (JScript)</title>
<style>
<!--
body {
   font-family: 'Verdana','Arial','Helvetica',sans-serif;
   BACKGROUND-COLOR:white;
   COLOR:black;
    }
-->
</style>
</head>

<body bgcolor="White">
<h1>Append and CreateParameter Methods Example (JScript)</h1>
<%
   if (iRoyalty > -1)
   {
      // Open the connection.
      var Connect = "Provider=sqloledb;Data Source=" +
      Request.ServerVariables("SERVER_NAME") + ";" +
      "Initial Catalog=Pubs;User Id=sa;Password=;"
      var cnn = Server.CreateObject("ADODB.Connection.2.5");
      cnn.Open(Connect);
      cnn.CursorLocation = adUseClient;
      
      var cmdByRoyalty = Server.CreateObject("ADODB.Command.2.5");
      var RsByRoyalty = Server.CreateObject("ADODB.Recordset.2.5");
      var RsAuthor = Server.CreateObject("ADODB.Recordset.2.5");
   
      cmdByRoyalty.CommandText = "byroyalty";
      cmdByRoyalty.CommandType = adCmdStoredProc;
      
      // Create the new parameter and append to
      // the Command object's parameters collection.
      var prmByRoyalty = cmdByRoyalty.CreateParameter("percentage", adInteger, adParamInput);
      cmdByRoyalty.Parameters.Append(prmByRoyalty);
      prmByRoyalty.Value = iRoyalty;
      
      cmdByRoyalty.ActiveConnection = cnn;
      
      // Execute the command.
      RsByRoyalty = cmdByRoyalty.Execute();
      
      // Display the results.
      RsAuthor.Open("Authors", cnn);
   
      var strMessage;      // used to build up each line before writing to document.

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

      }
   
      // Close table.
      RsByRoyalty.Close;
      RsAuthor.Close
   }
%>

<hr>


<form method="POST" action="ActiveConnectionJS.asp" id=form1 name=form1>
  <p align="left">Enter royalty percentage to find (e.g., 40): <input type="text" name="RoyaltyValue" size="5"></p>
  <p align="left"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
&nbsp;


</body>

</html>
<!-- EndAppendJS -->

See Also

Append Method | CreateParameter Method | Field Object | Fields Collection | Parameter Object