The Create Parameter Method

This method is used to manually create Parameter objects that can then be added to the Command object's Parameters collection. The CreateParameter object has the following syntax:

Set Parameter = command.CreateParameter([Name], [Type], [Direction], _

Name is the name of the parameter object. You can use this name to reference the Parameter object through the Command object's Parameters collection. When working with SQL Server, the name of a Parameter should be the same as the name of the stored procedure argument that it corresponds to.

Type indicates the data type of the parameter. It is specified as one of the DataTypeEnum constants. There are several dozen possible data types, so I will not go into them in any detail here. You will see a few of them in the examples section. The rest can be located in the ADO help file.

Direction is a ParameterDirectionEnum value that indicates whether the parameter will be used to pass data to an input argument, receive data from an output argument, or accept a return value from a stored procedure. Direction can be one of the following values:

□ adParamInput — The parameter represents an input argument

□ adParamInputOutput — The parameter represents an input/output argument

□ adParamOutput — The parameter represents an output argument

□ adParamReturnValue — The parameter represents a return value

Size is used to specify the size of Parameter in bytes, and is dependent on Parameter's data type. Value is used to provide an initial value for the Parameter.

The following code sample demonstrates how you can use the CreateParameter method in conjunction with the Parameters collection Append method to create a Parameter and append it to the Parameters collection with one line of code:

objCmd.Parameters.Append _

objCmd.CreateParameter("MyParam", adInteger, adParamInput, 0)

0 0

Post a comment