ADO Parameters Collection
The
Parameters Collection is a collection of the Parameter
objects associated with a specific Command object. Each
Parameter object provides detailed information about a single
parameter used in a stored procedure or a parameterized query.
Only the
Command object has a Parameters Collection.
Note that not all providers support stored procedures or parameterized queries,
nor do all providers return parameters to the Parameters Collection. For
such providers, the Parameters Collection will be left empty and the
collection will have to be manually populated.
If the provider will allow, you can populate the Parameters Collection by
using the Refresh method. In fact, if you try to access this collection
while it is empty or before you have called Refresh for the first time,
ADO will automatically call Refresh to populate the collection. It is
more efficient to provide the parameters, rather than having to call and obtain
this information from the provider. (Anything you can do to reduce calls to the
provider will improve performance.) You can add Parameter objects using
the Append property.
The collection starts numbering (indexing) with the number zero.
The Parameters Collection has two properties and three methods.
Properties
Count
The Count property returns a long value that is the number of items in the collection. The counting starts at zero. You can use this
value to loop through the collection by iterating from zero to the value of Count minus one.
Example:
intCountNumber = objCommand.Parameters.Count
Item
The Item property is used to return a
specific member of the Parameters Collection. The Index
parameter is the position (ordinal) number.
Example:
MyParameters =
objCommand.Parameters.Item(5)
Methods
Append
The Append method is used to add (append) a
Parameter object to the Parameters Collection.
Syntax:
Parameters.Append Object
Delete
The Delete method deletes a Parameter
object from the Parameters Collection.
Syntax:
Parameters.Delete
Index
Example:
objCommand.Parameters.Delete
3
Refresh
The Refresh method updates the Parameter
objects in the Parameters Collection with the latest information from the
provider.
Example:
objCommand.Parameters.Refresh
|