In the tutorial "Learning ASP in Ten Days", I gave a rough introduction to ADO, which can actually be said to be all there is to it. It only talks about the Open method in the Connection object to establish a physical connection to the data source and use the Close method to disconnect it; the changes made in the Recordset object using the AddNew, Update and Delete methods are mentioned in the Recordset object in the last page. AbsolutePage and RecordCount properties. Here I think it is necessary to talk about the methods and properties of various objects of ADO in a more systematic way. After all, ADO is not only used in ASP, but can also be used in VB and VC. The main objects I want to mention during these ten days are:
Connection object (represents an open connection to a data source.)
RecordSet object (Represents the complete set of records from a base table or the result of a command execution.)
As for the Parameter object and Command object that are closely related to stored procedures, we will discuss them in detail in future tutorials.
Let’s first talk about the methods of the Connection object:
1. Open method
connection.Open ConnectionString, UserID, Password, Options
ConnectionString Optional, string containing connection information.
UserID Optional, string containing the username used when establishing the connection.
Password is optional, a string containing the password used to establish the connection.
Options Optional, ConnectOptionEnum value. Determines whether the method returns after the connection is established (asynchronous) or before the connection is established (synchronously). Can be one of the following constants:
adConnectUnspecified (Default) Open the connection synchronously.
adAsyncConnect opens a connection asynchronously.
2.Execute method
connection.Execute CommandText, RecordsAffected
CommandText String containing the text of the SQL statement, table name, stored procedure, or specific provider to be executed.
RecordsAffected Optional, long variable to which the provider returns the number of records affected by the operation.
3. Close method
connection.Close
Use the Close method to close the Connection object to release all associated system resources.
Things to note are:
(1) Closing an object does not delete it from memory. You can change its property settings and open it again later.
(2) To completely delete the object from memory, set the object variable to Nothing.
(3) When using the Close method to close the Connection object, any active Recordset object associated with the connection will also be closed.
(4) After closing the Connection object, calling any method that needs to open a connection to the data source will generate an error.
Everyone should be familiar with the above three methods.
Let’s talk about the properties of the Connection object, briefly mention them.
1. Provider attribute Use the Provider attribute to specify the OLE DB provider.
It should be noted that specifying providers in multiple places when calling the Open method may have unpredictable consequences.
2. The ConnectionString property contains information used to establish a connection to the data source.
3. The ConnectionTimeout attribute indicates the time to wait during the connection establishment before terminating the attempt and generating an error, and a long integer value (in seconds) to wait for the connection to be opened. The default value is 15.
4. The Mode attribute indicates the available permissions to modify data in Connection.
Constant description
AdModeUnknown Default value. Indicates that the permission has not been set or cannot be determined.
AdModeRead indicates that permissions are read-only.
AdModeWrite indicates that permissions are write-only.
AdModeReadWrite indicates that permissions are read/write.
AdModeShareDenyRead prevents other users from opening connections with read permissions.
AdModeShareDenyWrite prevents other users from opening connections with write permissions.
AdModeShareExclusive prevents other users from opening connections.
AdModeShareDenyNone prevents other users from opening connections with any permissions.
Things to note are:
Use the Mode property to set or return the access rights that the provider is using on the current connection. The Mode property can only be set when the Connection object is closed.
Having said that today, let’s talk about the properties of the RecordSet object tomorrow.