Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1
that MySQL does not have (namely, stored procedures).

Execute() (^) This method will cause the execution of the commands in the
command text.
Prepared (^) A Boolean value (True or False) that indicates whether the
provider will save a copy of the command text in memory. This
can improve the performance of a query. MySQL supports this
option.
State (^) Indicates whether the Command object's connection is open or
closed.


Working with the Command Object


As explained earlier, the Command object has many different uses. To use the Command object, perform the
following steps:



  1. You must first declare a variable to hold your Command object:
    Dim mCmd

  2. Next, using the Server object’s CreateObject method, create the Command
    object:
    Set mCmd = Server.CreateObject("ADODB.Command")

  3. Tell the Command object which connection to use:
    mCmd.ActiveConnection = mConn

  4. Set some of the properties of the new Command object. This is where you tell
    what type of command you want to issue as well as set the timeout:

  5. mCmd.CommandType = 1

  6. mCmd.CommandTimeout = 40
    mCmd.CommandText = "SELECT * FROM Customers"

  7. Depending on what your command is, you can use the Execute method to
    accomplish your task. For example, if you were to DELETE a record from the
    Customers table, you could use the following sequence of events (the following
    assumes you have already opened a connection to a database using the mConn
    object):

  8. Dim mCmd

  9. Set mCmd = Server.CreateObject("ADODB.Command")

  10. mCmd.ActiveConnection = mConn

  11. mCmd.CommandType = 1

  12. mCmd.CommandText = "DELETE FROM Customers WHERE
    Customer_ID= 1345"
    mCmd.Execute
    As you can see, the Command object is how you convey your statements to the database. Now what if
    you wanted to see the results of a query? How would you go about getting that from a command? The
    answer is that you would use the Resultset object.


Resultset Object Properties and Methods


The Resultset object, like the other ADO objects, has many properties and methods. The methods and
properties of the Resultset object deal with the data that is returned from the database. Table 13.3 is a
listing of some of the properties and methods of the Resultset object.
Table 13.3 Resultset Object’s Methods and Properties


Method or Property Description
AddNew()
Adds a new record to an updateable recordset.

BOF, EOF (^) Returns either True or False, depending on whether you are at the
beginning of the recordset or at the end (BOF = beginning of file, EOF =
end of file).
Clone() (^) Creates a duplicate copy of the current recordset.
Close()
Closes the current recordset.

Free download pdf