The Prepare/Execute model assumes the following steps:
-
You make an on-the-fly request to the provider, instructing it to compile your
request.
-
The provider compiles your request.
-
The provider executes the compiled request.
-
The provider returns the result to you.
-
When you make the same request in the future during this session, the provider
repeats steps 3 and 4, using the already compiled statement.
You can make a request using the Prepare/Execute model by using a Command
object in the following steps:
STEP BY STEP
9.1 Making a Request Using the Prepare/Execute Model
-
Set the Command object's Prepared property to True.
-
Set the Command object's CommandType property to adCmdText if you are executing
a SQL statement, or adCmdTable if the request is just a table name (or skip this step
and use the Options parameter in step 4).
-
Set the Command object's CommandText property to the text of the SQL statement
that you want to execute (or skip this step and pass the SQL statement as an argument
to the Execute method in the following step).
-
Call the Command object's Execute method. If you did not set the CommandType
property in step 2, pass the appropriate value as the CommandType argument. If you
did not set the CommandText property in step 3, pass the SQL statement as the Options
argument (the third argument) to the Execute method.
The Prepared property of a Command object makes the difference between the Prepare/Execute
and the Execute Direct models. When the Prepared property is set to True, the provider compiles
the SQL statement to a temporary stored procedure before running it. The provider persists this
temporary stored procedure until the Command object is changed or destroyed
NOTE - Stored Procedures and Parameters: The
information under the section "Using Stored Procedures"
contains more information on how to program with stored procedures in the ADO
object model. Also see the section "Using the
Parameters Collection to Access Parameters for Stored Procedures" for more
information on how to work with a Command object's Parameters collection