Recommended: asp.net uses RAR to implement file compression and decompression If the RAR program is installed on the server, then asp.net can call RAR to implement file compression and decompression. However, it should be noted that since web programs cannot directly call client programs (unless ActiveX is used, ActiveX is almost abandoned), if you want to implement it,
8.2.5 Stream ObjectsStream objects are used to access the content of a node, such as an E-Mail message, or a web page. Use Stream objects to access the real content of a file or resource. Therefore, combining Record and Recordset objects can not only access files or email messages on the web server, but also access the corresponding content. In this way, you can create a mail customer that uses only ADO to access the mail system. This may not have many advantages, but it means you don't have to understand the mail system's API or object model, reducing learning detours.
Another use of Stream is XML, which can access a series of data (structured or semi-structured) as XML streams.
Stream objects are used to process binary data, so they can be used to process BLOB type data, such as image or large text data in a database.
Similarly, you will see more examples of Stream objects in Chapters 11 and 12 of this book.
8.2.6 Collection
There are some collections in the ADO object library, each with zero or more copies of the objects associated with it. You can use the same code structure to traverse these collections.
The syntax in VBScript is:
For Each object In Collection
' Do something with object
Next
For example, iterate over a Fields set of a Recordset object:
For Each objField In rs.Fields
Response.Write objField.Name & <BR>
Next
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
Fields collections have Field objects associated with recordsets or records. For a record set based on structured data, such as SQL data, the fields correspond to the columns in the data and contain the detailed content of the columns, such as name, data type, length, etc. I see a lot of examples about Fields collections in the next few chapters.
For semi-structured data, the properties of the object correspond to the fields. You will see more related introductions in Chapter 12.
2. Parameters Collection
The Parameters collection is only used by the Command object, determining 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 parameters that return information to ADO, because this way, it is not just a record set that returns from the stored procedure. For example, considering a complex stored procedure that updates multiple tables and then returns a record set, you can use an output parameter to show how many records have been updated.
Another reason to use parameters is performance issues, especially when only a single value needs to be returned from a stored procedure. In this case, there is no need to create a record set, just save a value, so there is no need to return the record set, and returning the value of the output parameter is a more efficient method.
In Chapter 9, you will see a detailed introduction to the Parameter collection.
3. Error collection
The Error collection contains 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 be considered a limitation because there is no need to explicitly define the Connection object, but the implicit Connection object can be accessed through the ActiveConnection properties of the Command, Recordset, and Record objects. For example:
For Each objError In rs.ActiveConnection.Errors
Response.Write objError.Name & <BR>
Next
Later in this chapter, the Error collection will be discussed in detail.
4. Properties Collection
To avoid confusion, the Properties collection is not displayed on the previous object model diagram. Its relationship with the object model is shown in Figure 8-5:
Figure 8-5 The relationship between property and object
The reason why Properties collections exist is because ADO is used to process many different data stores, with different characteristics. Constituting properties (Property) into a collection can enable them to be dynamically changed at any time according to different data providers. For example, Jet's OLE DB provider allows access to Jet's special security properties:
Set conDB = Server.CreateObject (ADODB.Connection)
conDB.Open DSN=Nwind
conDB.Properties (Jet OLEDB:Database Password) = LetMeIn
Other providers do not have this property, so it is unwise to add it to the Connection object as a static property. ADO populates the attribute collection with the provider default value based on the OLE DB provider used.
Although there are instructions for using the Properties collection here, the Properties collection is not described in detail in this book. For more information on the collection, see Professional ADO 2.5 Programming or ADO 2.5 Programming's Reference, both published by Wrox.
8.2.7 ADO constant
When using ADO, you will find that there are many predefined constants for numerous options, such as constants that define cursor type and lock type. Using languages like Visual Basic or Visual C, these constants will naturally be used once the ADO type library is referenced. In ASP, there are two options.
The first way to reference constants is to include them into an ASP file:
<!-- #INCLUDE FILE=adovbc.inc -->
You can copy the include file to a local directory, or reference it from the installation directory, with the default path to C:/Program Files/Common Files/System/ado (the above file contains the ADO constant for VBScript - for JScript, adojavas.Inc should be used). One shortcoming of using this method is that it will make the ASP page too large because it contains all the constants, many of which do not need to be used.
You can create your own containing files that only contain the required constants, but when you use ADO more and more functions, you may find that you need to constantly edit and maintain this file.
A better solution is to create a reference to the type library. This method does not require the constant to be included in the ASP file but can directly reference the constant:
<!-- METADATA TYPE=typelib FILE=C:/Program Files/
Common Files/System/ado/msado15.dll -->
Don't suspect that the name of this DLL is msado15.dll, which is the correct name, containing the latest version of ADO.
You can include this METADATA statement in each ASP file where you need it, or put it in a global.asa file so that each web page in the application can reference these constants.
8.3 Connecting to the data storage
If you need to access a data store, you should create a connection to the data store. As mentioned earlier: You can create a Connection object explicitly, or let ADO create a connection implicitly. For any method, you must know the details of the data storage.
Although the actual details used for connections vary, the actual methods of connections are the same for all types of data storage. This is not surprising, as different providers require different types of information. Before allowing users to access the data store, some providers require the user's certificate, while others accept the default security certificate.
There are several ways to connect to a data source:
·Connect string. Put the connection details in the string, or add the connection details directly to the command when opening the data store. The advantage of this approach is that the connection details will be retained in the ASP page. The disadvantages are that if you have more pages, you will be trapped in heavy maintenance work when changing the connection details. The solution is to create a string variable containing the connection details and put it in an ASP include file. In this way, there is only one instance of the connection string, but it can be consistent with other ASP pages. Another common technique is to store connection strings in the application into state variables, so that they can be used by all pages in the application.
· Data link file. This is a file with connection details (extension .udl). The advantage is that only one data link file is required for any data ASP page. To create a data link file, just create a new text file and rename it (to make sure Windows Explorer displays the file extension). Once the file has been renamed, you can open it (double-click) to display the Data Link Properties dialog box.
Share: ASP program to purify the network environment to filter dirty words Purify the network environment ASP program implements filtering swear words The following is the referenced content: <!--#include file=../conn/dbconn1.asp--><!--#include