Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

db_param

Associates the specified member variable with an input or output parameter and delimits the variable.

[ db_param( 
   ordinal, 
   paramtype="DBPARAMIO_INPUT", 
   dbtype, 
   precision, 
   scale, 
   status, 
   length
) ]

Parameters

ordinal
The column number (DBCOLUMNINFO ordinal) corresponding to a field in the rowset to which to bind data.
paramtype (optional)
The type to set for the parameter. Providers support only parameter I/O types that are supported by the underlying data source. The type is a combination of one or more DBPARAMIOENUM values:
  • DBPARAMIO_INPUT   An input parameter.
  • DBPARAMIO_OUTPUT   An output parameter.
  • DBPARAMIO_NOTPARAM   The accessor has no parameters. Setting eParamIO to this value in row accessors reminds the user that parameters are ignored.
dbtype (optional)
An OLE DB Type Indicator for the column entry.
precision (optional)
The precision to be used for the column entry. For details, see the description of bPrecision element of the DBBINDING structure
scale (optional)
The scale to be used for the column entry. For details, see the description of bScale element of the DBBINDING structure
status (optional)
A member variable used to hold the status of this column. The status indicates whether the column value is a data value or some other value, such as NULL. For possible values, see Status in the OLE DB Programmer's Reference.
length (optional)
A member variable used to hold the size of the column in bytes.

Attribute Context

Applies to class, struct, member, method, local
Repeatable No
Required attributes None
Invalid attributes None

For more information about the attribute contexts, see Attribute Contexts.

Remarks

db_param defines parameters that you use in commands; therefore you use it with db_command. For example, you can use db_param to bind parameters in SQL queries or stored procedures. Parameters in a stored procedure are denoted by question marks (?), and you should bind the data members in the order in which the parameters appear.

db_param delimits member data that can participate in OLE DB ICommandWithParameters-based binding. It sets the parameter type (input or output), OLE DB type, precision, scale, status, and length for the specified parameter. This attribute inserts the OLE DB consumer macros BEGIN_PARAM_MAP ... END_PARAM_MAP. Each member you mark with the db_param attribute will occupy one entry in the map in the form of a COLUMN_ENTRY.

db_param is used in conjunction with either the db_table or db_command attributes.

Example

The following example creates a command class based on the SalesbyYear stored procedure in the Northwind database. It associates the first parameter in the stored procedure with the m_RETURN_VALUE variable, and defines it as an output parameter. It associates the last two (input) parameters with m_Beginning_Date and m_Ending_Date.

The following example associates the nOutput variable with an output parameter.

// SalesbyYear.h
// Note that you must provide your own connection string:

[
   db_source(L"my_connection_string"),
   db_command(L"{ ? = CALL dbo.\"Sales by Year\"(?,?) }")
]
class CSalesbyYear
{
public:

   // Bind columns
   [ db_column(1, status=m_dwShippedDateStatus, length=m_dwShippedDateLength) ] DBTIMESTAMP m_ShippedDate;
   [ db_column(2, status=m_dwOrderIDStatus, length=m_dwOrderIDLength) ] LONG m_OrderID;
   [ db_column(3, status=m_dwSubtotalStatus, length=m_dwSubtotalLength) ] CURRENCY m_Subtotal;
   [ db_column(4, status=m_dwYearStatus, length=m_dwYearLength) ] TCHAR m_Year[31];

   // Bind parameters
   [ db_param(1, DBPARAMIO_OUTPUT) ] LONG m_RETURN_VALUE;
   [ db_param(2, DBPARAMIO_INPUT) ] DBTIMESTAMP m_Beginning_Date;
   [ db_param(3, DBPARAMIO_INPUT) ] DBTIMESTAMP m_Ending_Date;
};

For an example of this attribute used in an application, see the MantaWeb sample.

See Also

OLE DB Consumer Attributes | Attributes Samples

Show:
© 2015 Microsoft