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.
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.