|
|
|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98
Next, you use the data connections BOF (beginning-of-file) and EOF (end-of-file) methods to determine whether the current record within the recordset is the first or last record, respectively. If you are not at the beginning or end of the recordset, you can display the fields, for example. The following code uses a Do…While loop to print the transaction IDs in the recordset:
<%
If myDBConnection.EOF
=== you are at the end of the record set
Else If myDBConnection.BOF
=== you are at the beginning of the record set
Else
Do While Not myDBConnection.EOF === loop through the result set
Response.Write (myDBConnection(Transaction_ID) & <BR>)
Loop
End if
%>
The ADO object model includes the following objects, each of which is covered in detail in subsequent sections:
- ConnectionBy using the Connection object, you establish a connection with your applications data source. In addition, you can use the Connection object to send SQL commands for a database server to process.
- CommandThe Command object executes parameterized queries and stored procedures.
- ParameterYou pass parameters to a stored procedure by using the Parameter object.
- RecordsetThe Recordset object holds the data the server returns as a result of processing a SQL command.
- FieldThe Recordset object uses the Field object because each record returned will contain one or more fields.
- ErrorThe Error object logs any errors from the data source.
The Connection Object The Connection object establishes a connection with a system data source. In addition, you can use the Connection object to pass SQL instructions for the database server to process. Like most objects, Connection has a set of useful properties that you can reference. These include
- AttributeThe Attribute property specifies whether the database server will start a new transaction after the previous transactions commit or rollback.
- CommandTimeOutThe CommandTimeOut property specifies the amount of time the server will wait to process the command. The default is 30 seconds.
- ConnectionStringConnectionString specifies the connection string used to connect to the database.
- ConnectionTimeOutThe ConnectionTimeOut property specifies the amount of time to wait for a connection to the data source.
- DefaultDatabaseDefaultDatabase is set equal to the default database to use if your applications data source supports connecting to multiple databases.
- IsolationThe Isolation property specifies the isolation level of your applications connection to the data source.
- ModeYou use the Mode property to specify the connection type: either read-only or read/write.
- ProviderThe Provider property is used to determine the provider of the connection to the data source.
- VersionYou use the Version property to determine the ADOs version.
You can also perform operations on the Connection object by employing one of the following methods:
- BeginTransBy using the Connection objects BeginTrans method, you can initiate a new transaction. Transactions are useful for maintaining data integrity within the database.
- CommitTransThe CommitTrans method commits the current transaction to the database. If the commit is successful, your application will write all changes to the database since the previous CommitTrans or RollBackTrans.
- RollBackTransThe RollBackTrans method cancels the current transaction. As a result, all changes to the database will revert since the previous CommitTrans or RollBackTrans.
- CloseTo close your applications connection to the database, use the Close method.
- ExecuteThe Execute method is used to instruct the database server to execute a SQL command. If the Execute is successful, the database server will return a result set. You can then use the Recordset object to process the result set.
- OpenTo open a connection to your applications data source, use the Open method.
The Recordset Object In the ADO model, the Recordset object holds the results of a database query. You can create a Recordset object in a number of ways. You can create the object by using the Connection or Command objects, or by using the Recordset object itself. If you use the ADO Recordset object, you get to set the resulting recordsets properties. If you establish a Recordset using the Connection or Command object, you cannot set the resulting recordsets properties. Listing 33.5 shows an example of using the ADO Recordset to create a new Recordset object.
Listing 33.5 Creating a New Recordset object with ADO.Recordset
Set myRecordset=Server.CreateObject(ADO.Recordset)
myRecordset.Source=
myRecordset.RecordCount=20
myRecordset.Open
|