instead of the Microsoft constant because there is a bug within IIS that causes an error if
you use the constant.
If everything was supplied correctly and the SQL string in your Command object is valid, a recordset will
be opened containing the data you want. What you do after that is up to you. You can manipulate,
display, edit, or add records to the recordset.
There are four parameters that can be used when opening a recordset. They are the Source,
ActiveConnection, CursorType, and LockType. There is a fifth parameter, but it is never used. In
fact, Microsoft says not to use this parameter because it can produce errors.
The first parameter is the Source. As explained earlier, there are basically three types of sources. The
first, which is the recommended way, is to use a Command object as your Source. This provides the
most flexible way to open a recordset. The second way is to use an SQL statement as a source. The
final way is to use a table name as the source for your data in the recordset. What you use is up to you.
The recommended way is definitely the best way to go, but if you use the other methods, don’t forget to
supply the ActiveConnection.
The ActiveConnection, the second optional parameter in the Open method of a Recordset object,
is an open Connection object. If you are using a Command object whose active connection has
already been set, you can leave this option blank. However, if you do not supply a Command object as
your source, you must use a Connection object here.
The next parameter is the CursorType. This defines what actions are performed on the recordset and
how the data is displayed in the recordset. The following are the choices for this parameter:
Keyset—Data that has been added since this type of cursor was opened will not be
seen. This type of recordset will allow you to move forward and backward through
the recordset. Data can also be added or deleted.
Dynamic—This is the most flexible cursor available. You can freely move backwards
and forwards through the recordset. Any records that were deleted or added since
this type of recordset was opened will change the recordset. It is a mirror to the data
in the database.
Static—This type of recordset cannot be updated, nor will any changes made after
this recordset is created be visible. This type of recordset is generally used in
reporting or static displays. The default recordset is 0 —Forward only. This is same
as a static cursor, except that you can only move forward through the records. This
recordset is good for quick, one time passes through your data.
Lock—MySQL allows you to control locking via SQL statements; some databases do
not. In an attempt to make a heterogeneous environment, Microsoft has added this
option into the mix. You can specify what type of locking to use. The ODBC driver
will take care of issuing the commands for you. The following are the choices for
your locks:
o Read only—This allows you to only read the data, you can not alter it.
o Pessimistic locking—The ODBC driver issues whatever command
necessary to ensure the proper editing of records. It will lock the table
before any editing is done, and then will release the lock when the
update has been completed.
o Optimistic locking—The provider will only lock the table when the
Update method is called. The best choice is to use Pessimistic
locking. This will lock the tables when you use them. If you feel you
need to add more locking, issue the commands in a Command object.
Using the Meet-A-Geek Database on the Web
Now that you have looked at the ADO objects and seen what they can do, take a look at how to use them in
a typical real life situation. You are going to create a series of Active Server Pages that allow someone to
post a personal ad via a Web page. The data from the Web page will be used to populate a MySQL
database.
Setting Up the Web Page
The first step is to design the Web page. You'll use the same one that was used in your database design
example back on Day 3, "Designing Your First Database." The following is a partial list of some of the HTML
tags that were used to produce this page:
<form method="POST" action="PostAd.asp">
<p> To post your free ad, please answer the following questions.