Opomba:
The user interface has been simplified in Dreamweaver CC and later. As a result, you may not find some of the options described in this article in Dreamweaver CC and later. For more information, see this article.
An ASP command object is a server object that performs some operation on a database. The object can contain any valid SQL statement, including one that returns a recordset, or one that inserts, updates, or deletes records in a database. A command object can alter the structure of a database if the SQL statement adds or deletes a column in a table. You can also use a command object to run a stored procedure in a database.
A command object can be reusable, in the sense that the application server can reuse a single compiled version of the object to execute the command a number of times. You make a command reusable by setting the Prepared property of the Command object to true, as in the following VBScript statement:
mycommand.Prepared = true
If you know the command will be executed more than a few times, having a single compiled version of the object can make database operations more efficient.
Opomba:
Not all database providers support prepared commands. If your database does not support it, it might return an error when you set this property to true. It might even ignore the request to prepare the command and set the Prepared property to false.
A command object is created by scripts on an ASP page, but Dreamweaver lets you create command objects without writing a line of ASP code.
You can use Dreamweaver to create ASP command objects that insert, update, or delete records in a database. You supply the command object with the SQL statement or stored procedure that performs the operation on the database.
-
Enter a name for the command, select a connection to the database that contains the records you want to edit, and select the editing operation that you want the command to perform—Insert, Update, or Delete.
Dreamweaver starts the SQL statement, based on the type of operation you select. For example, if you select Insert, the dialog box looks like the following example:
-
Use the Variables area to define any SQL variables. Provide the name and run-time value. Specifying the type and size of each variable prevents injection attacks.
The following example shows an Insert statement that contains three SQL variables. The values of these variables are provided by URL parameters passed to the page, as defined in the Run‑Time Value column of the Variables area.
To get the Size value, use the Databases panel in Dreamweaver. Find your database in the Databases panel and expand it. Next, find the table you’re working with and expand it. The table lists the sizes for your fields. For example, it might say ADDRESS (WChar 50). In this example, 50 is the size. You can also find the size in your database application.
Opomba:
Numeric, Boolean and date/time data types always use -1 as the size.
To determine the Type value, see the following table:
Type in database
Type in Dreamweaver
Size
Numeric (MS Access, MS SQL Server, MySQL)
Double
-1
Boolean, Yes/No (MS Access, MS SQL Server, MySQL)
Double
-1
Date/Time (MS Access, MS SQL Server, MySQL)
DBTimeStamp
-1
All other types of text fields, including the MySQL text data types char, varchar and longtext
LongVarChar
check database table
Text (MS Access) or nvarchar, nchar (MS SQL Server)
VarWChar
check database table
Memo (MS Access), ntext (MS SQL Server), or fields that support large amounts of text
LongVarWChar
1073741823
For more information on the type and size of SQL variables, see www.adobe.com/go/4e6b330a.
-
Dreamweaver inserts ASP code in your page that, when run on the server, creates a command that inserts, updates, or deletes records in the database.
By default, the code sets the Prepared property of the Command object to true, which makes the application server reuse a single compiled version of the object every time the command is run. To change this setting, switch to Code view and change the Prepared property to false.
Although you can use server behaviors to build pages that modify databases, you can also use database manipulation objects such as stored procedures or ASP command objects to build the pages.
A stored procedure is a reusable database item that performs some operation on the database. A stored procedure contains SQL code that can, among other things, insert, update, or delete records. Stored procedures can also alter the structure of the database itself. For example, you can use a stored procedure to add a table column or even delete a table.
A stored procedure can also call another stored procedure, as well as accept input parameters and return multiple values to the calling procedure in the form of output parameters.
A stored procedure is reusable in the sense that you can reuse a single compiled version of the procedure to execute a database operation a number of times. If you know a database task will be executed more than a few times—or the same task will be executed by different applications—using a stored procedure to execute that task can make database operations more efficient.
Opomba:
MySQL and Microsoft Access databases do not support stored procedures.
You can use a stored procedure to modify a database. A stored procedure is a reusable database item that performs some operation on the database.
Before you use a stored procedure to modify a database, make sure the stored procedure contains SQL that modifies the database in some way. To create and store one in your database, consult your database documentation and a good Transact-SQL manual.
-
Opomba:
You must enter corresponding page parameters for each stored procedure parameter return value. Do not add page parameters unless there is a corresponding return value.
-
Select the Returns Recordset Named option, and then enter a name for the recordset; if the stored procedure returns a recordset, click the Test button to see the recordset that the stored procedure returns.
Opomba:
If the stored procedure returns a recordset and takes parameters, you must enter a value in the Default Value column in the Variables box to test the stored procedure.
Opomba:
You can use different test values to generate different recordsets. To change test values, click the Edit button for Parameter, and change the test value, or click the Edit button for Page Parameter and change the default value.
-
Select the Returns Status Code Named option, enter a name for the status code, if the stored procedure returns a status code return value. Click OK.
After you close the box, Dreamweaver inserts ColdFusion code in your page that calls a stored procedure in the database, when the code runs on the server. The stored procedure in turn performs a database operation, such as inserting a record.
If the stored procedure takes parameters, you can create a page that gathers the parameter values and submits them to the page with the stored procedure. For example, you may create a page that uses URL parameters or an HTML form to gather parameter values from users.
With ASP pages, you must add a command object to a page to run a stored procedure. For more information on command objects, see About ASP command objects.
-
After you close the dialog box, ASP code is inserted in your page. When the code runs on the server, the code creates a command object that runs a stored procedure in the database. The stored procedure in turn performs a database operation, such as inserting a record.
By default, the code sets the Prepared property of the Command object to true, which makes the application server reuse a single compiled version of the object every time the stored procedure is run. If you know the command will be executed more than a few times, having a single compiled version of the object can improve the efficiency of database operations. However, if the command will only be executed one or two times, using one might actually slow down your web application because the system has to pause to compile the command. To change the setting, switch to Code view and change the Prepared property to false.
Opomba:
Not all database providers support prepared commands. If your database does not support it, you might get an error message when you run the page. Switch to Code view and change the Prepared property to false.