What the header and META tags are doing in lines 10–50 has been discussed earlier. Let's skip to the
code that deals with the ADO objects.
As usual, you declare your variables and create the objects (lines 70–160).
Notice this time you are creating a Recordset object. It is good programming practice to name your
recordset after the data it will contain. It makes it easier to remember what the purpose of the recordset
is and to help identify it when you are using more than one recordset at a time.
Lines 170–220 set the variable of your Connection object. Because you’ve seen this a couple of times
previously, move on to the Command object. This time, you are going to issue an SQL statement that will
return a recordset with our Command object. Lines 230–270 of the code segment do just that.
Remember, you can issue any command that you could issue in the MySQL Monitor in the command
text. Here, you are issuing a SELECT statement, choosing to receive all the columns and all the rows
from the table.
Another way to accomplish this task is to use the table type instead of the text type as the type used in
the Command object’s CommandType property. You could use a 3 instead of a 1 to indicate a table is
going to be used. Then in the command text, all you would have to do is use the table's name. For
example, to use a table type command, you would do the following:
- Set the CommandType = 3
- Change the CommandText = "Customers"
This would return the exact same results as the SELECT * statement. This shows you the flexibility
ADO has to offer. You can do things a number of different ways. It's just a matter of preference.
The next part of the code opens the recordset (line 270). The first parameter of the Open method is the
Source. You chose to use the Command object as your source. The next parameter is the
ActiveConnection. Because you are using a Command object that already has an
ActiveConnection, you don't need to state one here. The next parameter is the type of cursor the
recordset will use. Because you are just going to display data and not alter it, you opt to use the default,
which is Forward Only. The next parameter is the LockType. Because you are using a static
recordset, you will use a Read Only type lock. This will free up the table for other people to use.
Lines 440–620 deal with walking through the recordset. This code is really straightforward. To walk
through the recordset, which means stepping through each record one at a time, you use a
Do...Until loop. This tests the condition first. If the condition proves False, it steps through the rest
of the loop. If not, it goes on without going through the loop. The loop contains the code that will output
the data in the recordset to the Web page. You use the Fields property of the recordset to do this. The
Fields property is really a collection of name=value pairs. You can refer to a value in a column by
using the name of the column, as you do in the code. Here, you display the current value of the
customer’s last name, first name, and state.
The last bit of code (lines 630 and 640) closes the recordset and then closes the connection.
As you can see, you can use Microsoft technology with MySQL in a multitude of ways. It is up to you
and your imagination. This marries two very diverse, yet capable technologies. You can have a MySQL
server running on a Linux platform and connect to it using ADO technology. This allows you to take
advantage of the best of both worlds. You get a stable, reliable, fast database engine, as well as an
application that can run on the world’s most popular desktop operating system. Everything has its place;
it's finding the best place that makes it all come together.
Summary
Today, you learned about ODBC—how it is Microsoft’s answer to a heterogeneous data environment, where
data access is the same no matter where or what database from which the data is coming. You learned that
to take advantage of ODBC, you needed to use some other tools. The tools you used in the examples were
ActiveX Data Objects, VBScript, and Active Server Pages.
You learned that there are three primary objects in ADO: the Connection object, Command Object,
and the Recordset object. You learned how they interacted with each other and about their methods
and properties.
You also learned about Active Server Page technology. You saw how an ASP could process data and
create pages dynamically.
You learned that VBScript is an easy language to use—that it is a subset of Visual Basic. You learned
how to use VBScript to manipulate and access the ADO objects.