This example uses the ActiveConnection, CommandText, CommandTimeout, CommandType, Size, and Direction properties to execute a stored procedure.
<!-- BeginActiveConnectionJS --> <% @LANGUAGE="JScript" %> <!-- Include file for JScript ADO Constants --> <!--#include File="adojavas.inc"--> <% var iRoyalty = parseInt(Request.Form("RoyaltyValue")); %> <html> <head> <title>ActiveConnection, CommandText, CommandTimeout, CommandType, Size, and Direction Properties</title> <style> <!-- BODY { font-family: 'Verdana','Arial','Helvetica',sans-serif; BACKGROUND-COLOR:white; COLOR:black; } .thead { background-color: #008080; font-family: 'Verdana','Arial','Helvetica',sans-serif; font-size: x-small; color: white; } .thead2 { background-color: #800000; font-family: 'Verdana','Arial','Helvetica',sans-serif; font-size: x-small; color: white; } .tbody { text-align: center; background-color: #f7efde; font-family: 'Verdana','Arial','Helvetica',sans-serif; font-size: x-small; } --> </style> </head> <body bgcolor="White"> <% if (iRoyalty > -1) { // Open the connection. var Connect = "Provider=sqloledb;Data Source=" + Request.ServerVariables("SERVER_NAME") + ";" + "Initial Catalog=Pubs;User Id=sa;Password=;" // Open a recordset on the author table using // a command object. var cnn = Server.CreateObject("ADODB.Connection"); var cmdByRoyalty = Server.CreateObject("ADODB.Command"); var RsByRoyalty = Server.CreateObject("ADODB.Recordset"); var RsAuthor = Server.CreateObject("ADODB.Recordset"); cnn.Open(Connect); cmdByRoyalty.CommandText = "byroyalty"; cmdByRoyalty.CommandType = adCmdStoredProc; cmdByRoyalty.CommandTimeOut = 15; prmByRoyalty = Server.CreateObject("ADODB.Parameter.2.5"); prmByRoyalty.Type = adInteger; prmByRoyalty.Size = 3; prmByRoyalty.Direction = adParamInput; prmByRoyalty.Value = iRoyalty; cmdByRoyalty.Parameters.Append(prmByRoyalty); cmdByRoyalty.ActiveConnection = cnn; RsByRoyalty = cmdByRoyalty.Execute(); 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"> <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> </body> </html> <!-- EndActiveConnectionJS -->
ActiveCommand Property | Command Object | CommandText Property | CommandTimeout Property | CommandType Property | Connection Object | Direction Property | Parameter Object | Record Object | Recordset Object | Size Property