ASP basic Knowledge Command object explain _php Foundation

Source: Internet
Author: User

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:

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

Five, the application instance of the Command object
1, this is a simple employee basic management system, its functions are: 1, add staff information, 2, change employee information, 3, delete employee data, retrieve employee information. It contains seven pages and a database. respectively:
1), Main page: Index.asp
2, add data page: add.htm
3), Save Add Data page: add.asp
4), change data page: update.asp
5), Save Change data page: update1.asp
6), delete Record page: detele.asp
7, retrieve employee Information page: shousho.asp
8), database: Rsgl.mdb. Use the Employee Basics table in this database.
2, the code for each page is as follows:
1), Main page: Index.asp. the functionality of the page is:
a), creating two objects, Connectiion objects and Recordset objects, to connect to the database and return a Recordset,
B), and create a table to make the Do The While loop statement displays the records in a table,
C), creates three hyperlinks, one to connect to add data pages, the other to connect to the change data page through the specified employee name, and a connection to the delete page through the specified employee name.

<% @ language= "VBScript"%>  

2), add Data page: add.htm.

This page is composed of a form that submits data to the Save Add Data page (add.asp).

 

3), Save Add Data page: add.asp.

The features of this page are:

A), using the Request object to obtain the value submitted from the Add.htm page;

b), create three objects (Connection object, Recordset object, and Instruction object), and five parameters, execute insert Insert command by calling parameters.

<% @ language= "VBScript"%>  


4), Change the data page: update.asp. the features of this page are:

A), create two objects, Connectiion objects and Recordset objects to connect to the database and return a recordset;

b), create a form that is intended to commit the changed data.

Cnn. connectionstring= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server. MapPath (".. /rsgl.mdb ") CNN. Open ssql= "SELECT * from Employee Basic table where Employee name = '" & A & "'" ' rst. Open ssql,cnn,1,1 set RST=CNN. Execute (ssql,,adcmdtext)%> 
<% @ language= "VBScript"%> <% ' ***************** extract the value from the submission form *************************** Dim name,department, Addr,tel,email Name=trim (Request.Form ("Txtname")) Department=trim (Request.Form ("Txtdepartment")) Addr=Trim (
Request.Form ("Txtaddr")) Tel=trim (Request.Form ("Txttel")) Email=trim (Request.Form ("Txtemail"))%>  


6), delete data page: detele.asp.

A), use the Request object to obtain the name of the employee to be deleted;

B, create three objects (Connection object, Recordset object, and instruction object) and a parameter to delete the record by the value specified by the parameter;

c), give the Delete Success prompt box.

<title> change record </title>  


7), Search employee Information page: shousho.asp.

A), using a list box to submit the condition of the search;

B, create three objects (Connection objects, Recordset objects, and instruction objects) and a parameter, use the Value property of the Parameter object to assign the values of the form submission to the parameters;

c), use a For loop statement to display each record in the retrieved recordset through a table.

<% @ language= "VBScript"%>  

The above is about the ASP basic Knowledge Command object of the introductory tutorial, I hope to learn some help, a lot of exchanges and discussion.

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.