This example demonstrates the Execute method when run from both a Command object and a Connection object. It also uses the Requery method to retrieve current data in a Recordset, and the Clear method to clear the contents of the Errors collection. (The Errors collection is accessed via the Connection object of the ActiveConnection property of the Recordset.) Name the file ExecuteJS.asp.
<!-- BeginExecuteJS --> <% @LANGUAGE="JScript" %> <% strLastName = new String(Request.Form("AuthorLName")); if (strLastName.indexOf("undefined") > -1) strLastName = ""; %> <html> <head> <title>Execute, Requery and Clear Methods Example (JScript)</title> <style> <!-- BODY { font-family: 'Verdana','Arial','Helvetica',sans-serif; BACKGROUND-COLOR:white; COLOR:black; } --> </style> </head> <body bgcolor="White"> <h1>Execute, Requery and Clear Methods Example (JScript)</h1> <% if (strLastName.length > 0) { // 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 cmdAuthor = Server.CreateObject("ADODB.Command"); var RsAuthor = Server.CreateObject("ADODB.Recordset"); cnn.Open(Connect); cmdAuthor.CommandText = "SELECT * FROM Authors WHERE au_lname = ?"; cmdAuthor.Parameters.Append(cmdAuthor.CreateParameter("Last Name", adChar, adParamInput, 20, strLastName)); cmdAuthor.ActiveConnection = cnn; RsAuthor = cmdAuthor.Execute(); var strMessage; // used to build up line before writing to document. while (!RsAuthor.EOF) { // 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. RsAuthor.MoveNext; } // Close table. RsAuthor.Close; } %> <hr> <form method="POST" action="ActiveCommandJS.asp" id=form1 name=form1> <p align="left">Enter last name of author to find (e.g., Ringer): <input type="text" name="AuthorLName" size="40"></p> <p align="left"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body> </html> <!-- EndExecuteJS -->
Clear Method | Command Object | Connection Object | Error Object | Execute Method (ADO Command) | Execute Method (ADO Connection) | Recordset Object | Requery Method