Export (0) Print
Expand All

db_column

Binds a specified column to a variable in the rowset.

[ db_column( 
   ordinal, 
   dbtype, 
   precision, 
   scale, 
   status, 
   length 
) ]

Parameters

ordinal
The ordinal column number (DBCOLUMNINFO ordinal) or column name (ANSI or Unicode string) corresponding to a field in the rowset to which to bind data. If you use numbers, you can skip consecutive ordinals (for example: 1, 2, 3, 5). The name may contain spaces if the OLE DB provider you use supports it. For example, you can use either of the following formats:
[db_column(2)] TCHAR szCity[30];
[db_column(L"city_name")] TCHAR szCity[30];
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 the 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
Repeatable No
Required attributes None
Invalid attributes None

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

Remarks

db_column binds the specified table column to a variable in the rowset. It delimits member data that can participate in OLE DB IAccessor-based binding. This attribute sets up the column map normally defined using the OLE DB consumer macros BEGIN_COLUMN_MAP, END_COLUMN_MAP, and COLUMN_ENTRY. These manipulate the OLE DB DBBINDING structure to bind the specified column. Each member you mark with the db_column attribute will occupy one entry in the column map in the form of a column entry. Therefore, you call this attribute where you would put the column map, that is, in the command or table class.

Use db_column in conjunction with either the db_table or db_command attributes.

Example

The following example binds a column in a table to a long data member and specifies status and length fields.

// Example 1
[ db_command(L"Select * from Products") ]
class CProducts
{
   [ db_column(1, status=m_dwProductIDStatus, length=m_dwProductIDLength) ] LONG m_ProductID;

   DBSTATUS m_dwProductIDStatus;
   DBLENGTH m_dwProductIDLength;
};

The following example binds four columns to a long, a character string, a timestamp, and a DB_NUMERIC integer, in that order.

// Example 2
[ db_command(L"Select * from Products") ]
class CProducts
{
   [db_column(1)] LONG m_OrderID;
   [db_column(2)] TCHAR m_CustomerID[6];
   [db_column(4, DBTIMESTAMP)] DBTIMESTAMP m_OrderDate;
   [db_column(7, DBTYPE_NUMERIC, 7, 3)] DB_NUMERIC m_ShipVia;
};

For an example of this attribute used in an application, see the samples AtlAgent, MultiRead, and MantaWeb.

See Also

OLE DB Consumer Attributes | Class Attributes | Attributes Samples

Show:
© 2014 Microsoft