--- title: "ActiveCommand Property Example (JScript) | Microsoft Docs" ms.prod: sql ms.prod_service: connectivity ms.technology: connectivity ms.custom: "" ms.date: "01/19/2017" ms.reviewer: "" ms.topic: conceptual dev_langs: - "JScript" helpviewer_keywords: - "ActiveCommand property [ADO], JScript example" ms.assetid: be09e2af-ba31-4168-8ccd-2461bb24e49a author: MightyPen ms.author: genemi --- # ActiveCommand Property Example (JScript) This example demonstrates the [ActiveCommand](../../../ado/reference/ado-api/activecommand-property-ado.md) property. Cut and paste the following code to Notepad or another text editor, and save it as **ActiveCommandJS.asp**. ``` <%@LANGUAGE="JScript" %> <%// use this meta tag instead of adojavas.inc%> <% // user input strName = new String(Request.Form("ContactName")) %> ActiveCommand Property Example (JScript)

ActiveCommand Property Example (JScript)

<% if (strName.length > 0) { // connection and recordset variables var Cnxn = Server.CreateObject("ADODB.Connection") var strCnxn = "Provider='sqloledb';Data Source=" + Request.ServerVariables("SERVER_NAME") + ";" + "Initial Catalog='Northwind';Integrated Security='SSPI';"; var cmdContact = Server.CreateObject("ADODB.Command"); var rsContact = Server.CreateObject("ADODB.Recordset"); // display variables var strMessage; try { // open connection Cnxn.Open(strCnxn); // Open a recordset using a command object cmdContact.CommandText = "SELECT ContactName FROM Customers WHERE City = ?"; cmdContact.ActiveConnection = Cnxn; // create parameter and insert variable value cmdContact.Parameters.Append(cmdContact.CreateParameter("ContactName", adChar, adParamInput, 30, strName)); rsContact = cmdContact.Execute(); while(!rsContact.EOF){ // start new line strMessage = "

"; // get data strMessage += rsContact("ContactName") // end the line strMessage += "

"; // show data Response.Write(strMessage); // get next record rsContact.MoveNext; } } catch (e) { Response.Write(e.message); } finally { // 'clean up if (rsContact.State == adStateOpen) rsContact.Close; if (Cnxn.State == adStateOpen) Cnxn.Close; rsContact = null; Cnxn = null; } } %>

Enter city of customer to find (e.g., Paris):

``` ## See Also [ActiveCommand Property (ADO)](../../../ado/reference/ado-api/activecommand-property-ado.md) [Command Object (ADO)](../../../ado/reference/ado-api/command-object-ado.md) [Recordset Object (ADO)](../../../ado/reference/ado-api/recordset-object-ado.md)