ASP Getting Started tutorials-command objects

Source: Internet
Author: User
Tags numeric value table name

The COONAMD object defines the commands that will be executed on the data source, can be used to query the database table and return a recordset, and can be used to add, change, and delete database tables.

First, use the command object steps:

When using the command object in an ASP page to process data, you should first set the command type, command text, and related active database connections, and pass the command arguments through the Parameter object, and then execute the SQL statement or call the stored procedure by calling the Execute method. To complete the retrieval, add, change, and delete tasks for the database records. The steps are as follows:

1, use the ActiveCommand property to set the related database connection;

2, use the CommandType property to set the command type;

3, use the CommandText attribute to define the executable text of the command (for example, SQL statement);

4, use the CommandTimeout property to set the command timeout time;

5, use the Execute method to execute the command.

Second, the Command object's properties:

Property Description/Format/comment
tr>
1, this property indicates which Connection object the specified Command object currently belongs to.

2, this property sets and returns a string that contains a defined connection or Connection object.

3, the property is readable and writable.

setcmd.activeconnection=cnn
1, cmd: Defined Command object; 2, CNN: The Connection object to connect to.
This property specifies the command type to optimize performance, which can set and return one of the following values:

1, adCmdText: Indicates that an SQL statement is being processed;

2, ad Cmdtable: Indicates that a table is being processed;

3, adCmdStoredProc: Indicates that a stored procedure is being processed;

4, Adcmdunknow: means not recognized, it is the default value.

1, cmd: Defined Command object; 2, adCmdText : Indicates that an SQL statement is being processed.
CommandText
This property defines the text of the command that will be sent to the provider. It can set and return a string value that contains a provider command, such as a SQL query statement, a table name, or a stored procedure call.
Cmd.commandtext=sqlstring
1. CMD: Command object defined, 2, SQL query string (that is, an SQL statement).
CommandTimeout
This property specifies the amount of time (in seconds) to wait while executing a command before terminating the attempt or generating an error. The default value is 30 seconds.
Cmd.commadntimeout=n
N: The number of seconds to set.
    

Three, the Command object method----execute

This method executes the query specified in the CommandText property. The grammatical format is divided into the following two forms.

1, for the Command returned by line:

Set recordset=command.Execute(RecordsAffected,Parameters,Options)

2. For Command not to be returned by line:

command.Execute RecordsAffected,Parameters,Options

Where the parameter recordsaffected is the number of records that are affected by the provider return operation. Rarameters The parameter values that are passed by using SQL statements. Options indicate how the provider assigns a value to the CommandText property of a Command object.

Iv. Use of Parameters collections

The command object has a Parameters collection of Parameter objects that represent the parameters or arguments associated with a Command object that is based on a parameterized query or stored procedure. You can pass the required data to a parameterized query by creating a Parameter object and adding it to the Parameter collection. The steps for using the Parameter collection are as follows:

To use the Parameter collection
Steps Description/Format/comment

1,

Creating Parameter Objects

use CreateParameter method to create a new Parameter object with the specified name, type, orientation, size, and value.
set Parameter=command. CreateParameter (name,type,direction,size,value)
type specifies the data type of the Parameter object and can be assigned a value using a symbolic constant. For example:

* Addate: Represents a date value;

* adinteger: A signed integer representing 4 bytes;

* Addecimal: An exact numeric value with fixed precision and range;

* addouble: Double-precision floating-point value ;

* adVarChar: Represents a String value. The

Direction parameter specifies the Parameter object type, and you can set or return one of the following values:

* adParamInput: Specified as input parameter (default);

* adParamOutput: Specified as output parameter ;

* adParamInputOutput: Specified as input and output parameters;

* adParamReturnValue: Specified as return value. The

* Size Specifies the maximum length of the parameter value, the character or number of bytes. The

* value specifies the value of the Parameter object.

2,

To add a parameter object to the Parameters collection

Use the Addend method to add the created Parameter object to the Parameters collection.
Comman. Parameters.addend Object
parameter specifies the name of the Parameter object.

3,

Assigning values to a parameter

Assign a value to a parameter using the value of the Parameter object.
Prmname.value=parametervalue
The parameter parametervalue is the value to assign to the parameter.

4,

Delete Parameter Object

Use the Parameter method to remove a Parameter object from the Parameters collection.
Parameter.delete Index
The index parameter specifies the name of the Parameter object to delete, or the position index value of the object in the Parameters collection.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.