The method of using ADO Command object to query Dynamic data of Web database

Source: Internet
Author: User
Tags web database

The method of using ADO Command object to query Dynamic data of Web database
★ Lin Biying
As we all know, because of the advent of ASP technology, the application of intranet is more extensive and in-depth. A large number of enterprises have established an enterprise internal comprehensive query system, how to quickly and accurately query enterprise internal information is to write web-based technology applications must solve the main problems. ASP provides the 3 main object recordsets, connection, and command that are built into ADO to manipulate the Web database. The main function of connection is to establish a link with the Web database; The main function of the command is to send requests to the Web database for data queries; The main function of the recordset is to establish the result set of the data query. Since ADO is almost tailor-made for web database applications, the command object has a powerful function in data querying. It can not only send general SQL instructions to the Web database server, but also can transfer parameters of the SQL instructions, more importantly, can also transmit stored procedures, so can develop more efficient database Web pages.

Main attributes and methods of command object
In order to further expound the function of data query of command object, it is necessary to introduce some properties and methods of command object which are closely related to data query.
Property:
(1) CommandText: Specify data query information. Can be SQL statements, stored procedures.
(2) CommandType: Specifies the type of data query. You can take four sets of values.
(3) ActiveConnection: Establish link relationship with connection channel.
Method:
(1) CreateParameter: Creates a new Parameter object.
(2) Execute: A data query is presented to the database. The command object can create a new parameter object using the CreateParameter method, and then add the new Parameter object to the parameters data collection using the Append method of the Parameters object. The results are: establish a parameter named contract number, the data type is character type, length is 10, parameter allowed read-write mode for input, parameter value is "1000030005" parameters object, and then add this parameter to parameters data collection.
The Command object executes a database query with the Execute method, and the Execute method allows the specified parameters to be passed in to achieve dynamic Data queries.

Several methods of implementing Dynamic Data query with Command object
Implementing a Dynamic Data query with the Command object first requires that the CommandText attribute value must be a SQL instruction with parameters or a stored procedure with parameters, where the argument must be the part of the query information that is allowed to pass in the value. Another is to call the Execute method with an array of parameter values (format three) or to store the parameter values in the parameters data collection of the Command object, and then invoke the Execute method of the Command object.
Command objects can have multiple parameter child objects to store related parameters, all of which belong to the parameters data collection. You can write parameter values to the parameters data collection in the following ways.
Suppose you already have a SQL Server database Bcdata, which has a data table of Gcht, 3 data fields, GCHTBH (Project contract number), GCMC (contract name), Htje (contract amount). Use the Command object to inquire about the 1999 and 2000 Engineering contract profile.
(1) Call the parameters Refresh method, get all the parameter child objects conforming to the CommandText attribute, and then deposit the known parameter values into the corresponding child objects.
(2) invokes the CreateParameter method of the Command object, creates a new parameter object, and attaches itself to the parameters data collection within the Command object. Then call the Append method of the parameters data collection to add the new parameter child object to the data collection.

Conclusion
The connection object of ADO is to submit the data query information with the Execute method, and the Recordset object is to submit the data query information with the open method, although the data query information that they submit can contain the variable but is not really the parameter pass in the sense. It is also easy to make mistakes when combining SQL instructions with variables, most importantly, they do not support fields that contain memo types in the submitted data query information. Whether the parameter data query information or stored procedures, Command object status is very important, as long as the command object is used well, the overall database page design will add a lot of flexibility and convenience.



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.