ASP 3.0 Advanced Programming (37)

Source: Internet
Author: User
Tags add define object sql object model ole string variable
Programming | Advanced 8.2.5 Stream objects
Stream object is used to access the contents of a node, such as an e-mail message, or a Web page. Use the Stream object to access the real content of a file or resource. Therefore, combined with the record and Recordset objects, you can access not only the file or email messages on the Web server, but also the appropriate content. This allows you to create a mail client that only uses ADO to access the messaging system. This may not have many advantages, but it means that there is no need to understand the API or object model of the messaging system, reducing the detours in learning.
Another use of stream is XML, which can access a series of data as XML streams (structured or semi-structured).
The stream object is used to process binary data, so it can be used to work with blob-type data, such as images in a database or large text data.
Again, in chapters 11th and 12 of this book you will see more examples of stream objects.

8.2.6 Collection
There are collections in the ADO object library, each of which has 0 or more copies of objects associated with it. You can use the same code structure to traverse these collections.
The syntax in VBScript is:
For all object in Collection
' Do something with object
For example, iterate through the fields set of a Recordset object:
For Each objfield in Rs. Fields
Response.Write objField.Name & "<BR>"
If you select JScript, you can use the enumerator object:
for (Objfield = new Enumerator (Rs. Fields);
!objfield.atend (); Objfield.movenext ())
Response.Write (Objfield.item (). Name + ' <BR> ');
1. Fields collection
The Fields collection has a Field object associated with a recordset or record. For a recordset based on structured data, such as SQL data, the field corresponds to a column in the data and contains the details of the column, such as name, data type, length, and so on. See a lot of examples of fields collections in the next few chapters.
For semi-structured data, the properties of the object correspond to fields. In the 12th chapter you will see more relevant introductions.
2. Parameters Collection
The Parameters collection is used only by the command object to determine the parameters in the stored command. stored procedures in SQL databases frequently use parameters and allow data to be passed in and out of predefined SQL statements. It is useful if you have a parameter that returns information to ADO because it returns more than a recordset from a stored procedure. For example, to consider a complex stored procedure that updates multiple tables and then returns a Recordset, you can display the number of records updated with an output parameter.
Another reason to use parameters is a performance problem, especially if you only need to return a single value from a stored procedure. In this case, there is no need to create a recordset, just save a value so that you do not need to return the recordset, and returning the value of the output parameter is a more efficient method.
In the 9th chapter you will see a detailed introduction to the parameter collection.
3. Error collection
The error collection contains the details of the last ADO or OLE DB Provider error caused by running the command and can only be accessed by the Connection object. This may feel like a limitation because you do not have to explicitly define the connection object, but you can access the implied connection object through the command, Recordset, and the ActiveConnection properties of the Record object. For example:
For each objerror in Rs. Activeconnection.errors
Response.Write & "<BR>"
The error collection is discussed in detail later in this chapter.
4. Properties collection
To avoid confusion, the Properties collection is not shown on the previous object model diagram. Its relationship to the object model is shown in Figure 8-5:
Figure 8-5 the relationship between property and object
The Properties collection exists because ADO is used to handle many different data stores and has different characteristics. A property is made into a collection that can be dynamically changed according to the data provider. For example, the OLE DB Provider for Jet allows access to jet's special security properties:
Set condb = Server.CreateObject ("ADODB. Connection ") "Dsn=nwind" ("Jet oledb:database Password") = "Letmein"
The other provider does not have this attribute, so it is unwise to add it to the connection object as a static property. ADO populates the property collection with provider defaults based on the OLE DB provider that is being used.
Although there is a description of the use of the Properties collection, it is not intended to describe the Properties collection in detail in this book. For more information on this collection, see "Professional ADO 2.5 Programming" or "ADO 2.5 programming ' Reference", both of which are published by Wrox.

8.2.7 ADO constant
When using ADO, there are many predefined constants for many options, such as constants that define cursor types and lock types. With languages like Visual Basic or Visual C + +, these constants are used naturally once the ADO type library is referenced. There are two options for different situations in the ASP.
The first way to reference constants is to include them in an ASP file:
<!--#INCLUDE file= ""-->
You can either copy the containing file to the local directory, or reference it from the installation directory, and the default path is C:\Program Files\Common Files\System\ado (the above file contains the ADO constants for VBScript-for JScript, You should use Adojavas. Inc.). The disadvantage of using this method is that the ASP page becomes too large, because it contains all the constants, many of which are not needed.
You can create your own containing files that contain only the constants you need, but more and more of the functionality of ADO is likely to find that you need to constantly edit and maintain this file.
A better solution is to create a reference to a type library that does not need to include constants in the ASP file and can refer directly to constants:
<!--METADATA type= "typelib" file= "C:\Program files\
Common Files\system\ado\msado15.dll "-->
Do not suspect that the name of this DLL is Msado15.dll, which is a correct name, containing the latest version of ADO.
You can include this metadata statement in each ASP file where you need it, or put in a Global.asa file so that each Web page in your application can reference these constants.

8.3 Connecting to the data store
If you need to access a data store, you should create a connection to the data store. As mentioned earlier: You can explicitly create a connection object, or let ADO implicitly create a connection. For any of these ways, you must know the details of the data store.
Although the actual details used for the connection are different, the actual method of connection is the same for all types of data storage. This is not surprising, because different providers require different types of information. Before allowing a user to access the data store, some providers require a user's certificate, while others accept the default security certificate.
There are several ways to connect to a data source:
· The connection string. Put the details of the connection in the string, or add the connection details directly to the command when you open the data store. The advantage of this approach is that the details of the connection will remain in the ASP page. Deficiencies, if you have more pages, in the change of connection details, will be bogged down in heavy maintenance work. The solution is to create a string variable that contains the details of the connection and put it in an ASP containing file, so that there is only one instance of the connection string, but it can be maintained in accordance with other ASP pages. Another common technique is to store the connection strings in an application in a state variable, which can be used by all pages in the application.
· Data link file. This is a file with connection details (. udl extension). The advantage is that the ASP page for any data requires only one data link file. To create a data link file, simply create a new text file and rename it (to ensure that Windows Explorer displays the file name extension). Once you have renamed the file, you can open it (double-click) to display the Data Link Properties dialog box. To

[1] [2] Next page

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