Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the properties and methods of command object

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today I will show you how to analyze the properties of command objects and their methods. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.

But I personally think that when you want to switch to command objects, please think carefully. First of all, be sure to enter ADO completely, which will not take much time and effort. As we all know, due to the emergence of ASP technology, the application of Intranet is more extensive and in-depth. A considerable number of enterprises have established internal comprehensive query systems.

The main function of Connection is to establish the link with WEB database; the main function of Command is to transmit the request of data query to WEB database; the main function of Recordset is to establish the result set of data query. Because ADO is almost tailor-made for the application of WEB database, the Command object in it has powerful function in data query. It can not only send general SQL instructions to WEB database server, but also transmit SQL instructions with parameters, and more importantly, it can also transfer stored procedures, so it can develop more efficient database web pages.

I. the main properties and methods of the command object

In order to further elaborate the data query function of Command object, it is necessary to introduce some properties and methods of Command object which are closely related to data query.

Attributes:

(1) CommandText: specify data query information. Can be SQL statements, stored procedures.

(2) CommandType: specifies the type of data query You can take four set values.

(3) ActiveConnection: establish a link with the Connection channel.

Methods:

(1) Createparameter: create a new parameter object.

(2) Execute: put forward data query to the database. The Command object can use the Createparameter method to create a new parameter object, and then use the append method of the parameters object to add the new parameter object to the parameters data collection.

The execution result is: establish a parameter object whose name is contract number, data type is character type, length is 10, the allowed read and write mode of the parameter is input, and the parameter value is "1000030005". Then add this parameter to the parameters data collection, the Command object executes the database query with the Execute method, and the Execute method allows you to pass in the specified parameters to achieve the dynamic data query.

2. Several methods to realize dynamic data query with command object.

To realize dynamic data query with command object, first of all, the value of commandtext attribute must be a SQL instruction with parameters or a stored procedure with parameters, and the parameters referred to here must be the part of the query information that allows input values.

The second is to call the execute method with an array of parameter values (format 3) or store the parameter values in the parameters data collection of the command object, and then call the execute method of the Command object. Command objects can have multiple parameter sub-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 there is already a SQL Server database bcdata, in which a data table is gcht and there are three data fields, namely gchtbh (engineering contract number), gcmc (contract name) and htje (contract amount). Use command object to query the profile of engineering contracts in 1999 and 2000.

Call the refresh method of parameters to get all the parameter sub-objects that match the commandtext property, and then store the known parameter values in the corresponding sub-objects.

(2) call the createparameter method of the command object to establish a new parameter object and attach it to the parameters data collection in the command object. Then call the append method of the parameters data collection to add the new parameter sub-object to the data set.

These are all the contents of how to analyze command object properties and their methods. For more information about how to analyze command object properties and methods, you can search the previous articles or browse the following articles to learn! I believe the editor will add more knowledge to you. I hope you can support it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report