ADO Command Object Methods

[Previous] [Next]

Now let's take a look at the methods available on the Command object.

Command Object Methods
Method NameDescription
CancelCancels an asynchronous query
CreateParameterCreates a Parameter object for the Command object's Parameters collection
ExecuteExecutes your query

Cancel Method

The Cancel method allows you to terminate the execution of an asynchronous query. Keep in mind that if you execute the query using the asynchronous fetching option, canceling the query after the ExecuteComplete event of the Connection object has fired will have no effect.

CreateParameter Method

The CreateParameter method returns a Parameter object. If you're using a parameterized query, you can populate the Parameters collection for the Command object by using the Append method on the Parameters collection combined with the CreateParameter method on the Command object. Here are the parameters that the CreateParameter method supports:

  • Name This optional parameter accepts a string that represents the name of the parameter.
  • Type This optional parameter accepts a value from DataTypeEnum for the parameter's data type. For information on DataTypeEnum values, see the ADO documentation in the Platform SDK Help.
  • Direction This optional parameter accepts a value from ParameterDirectionEnum. It specifies the direction (input or output) for the parameter.
  • Size This optional parameter accepts a long value to specify the maximum size of the parameter.
  • Value This optional parameter accepts a Variant that specifies the value for the parameter.

The parameters on the CreateParameter method correspond to most of the properties on the Parameter object that you're liable to set. I'll describe these parameters in more detail later in the chapter when we cover the Parameter object. Perhaps the only properties you might need to set on the Parameter object that aren't available as parameters on the CreateParameter method are the NumericScale and Precision properties.

Execute Method

As its name implies, the Execute method executes the query your Command object contains. By default, this method will return a Recordset object with the results of your query. It has the following parameters:

  • RecordsAffected This optional parameter accepts a long value that returns the number of records affected by the query.
  • Parameters This optional parameter accepts a Variant array that specifies the parameters for the query.
  • Options This optional parameter accepts a long value. You can supply a value from CommandTypeEnum and/or values from ExecuteOptionEnum.

The initial parameter, RecordsAffected, will contain a long integer that indicates the number of records affected by your query. If you're using action queries to update data in your database, you'll probably want to know how many records your query modified.

The Execute method also takes a parameter, Parameters, that you can use to supply values for the parameters of your query without having to use the Parameters collection. This parameter on the Execute method accepts a Variant array of values and/or variables that correspond to the items in your Command object's Parameters collection. Values supplied in Parameters will override the values in the Parameters collection.

Just as with the Options parameter of the Recordset.Open and Connection.Execute methods, you can use this final parameter of the Execute method with constants from CommandTypeEnum and/or ExecuteOptionEnum (see Chapter 4). The parameter is a bitmask, so you can combine appropriate constants such as adCmdText + adExecuteNoRecords. You can also specify a value or values from ExecuteOptionEnum in this parameter to execute your command asynchronously.



Programming ADO
Programming MicrosoftВ® ADO.NET 2.0 Core Reference
ISBN: B002ECEFQM
EAN: N/A
Year: 2000
Pages: 131
Authors: David Sceppa

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net