db_column
Binds a specified column to a variable in the rowset.
[ db_column( ordinal, dbtype, precision, scale, status, length ) ]
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.
When the consumer attribute provider applies this attribute to a class, the compiler will rename the class to _YourClassNameAccessor, where YourClassName is the name you gave the class, and the compiler will also create a class called YourClassName, which derives from _YourClassNameAccessor. In Class View, you will see both classes.
For examples of this attribute used in an application, see the samples AtlAgent, and MultiRead.
This sample binds a column in a table to a long data member and specifies status and length fields.
// db_column_1.cpp
// compile with: /LD
#include <atlbase.h>
#include <atlplus.h>
#include <atldbcli.h>
[ db_command(L"Select * from Products") ]
class CProducts {
DBSTATUS m_dwProductIDStatus;
DBLENGTH m_dwProductIDLength;
[ db_column("1", status="m_dwProductIDStatus", length="m_dwProductIDLength") ] LONG m_ProductID;
};
This sample binds four columns to a long, a character string, a timestamp, and a DB_NUMERIC integer, in that order.
// db_column_2.cpp
// compile with: /LD
#include <atlbase.h>
#include <atlplus.h>
#include <atldbcli.h>
[ db_command(L"Select * from Products") ]
class CProducts {
[db_column("1")] LONG m_OrderID;
[db_column("2")] TCHAR m_CustomerID[6];
[db_column("4")] DB_NUMERIC m_OrderDate;
[db_column("7", dbtype="DBTYPE_NUMERIC")] DB_NUMERIC m_ShipVia;
};
Applies to | class, struct, member, method |
Repeatable | No |
Required attributes | None |
Invalid attributes | None |
For more information about the attribute contexts, see Attribute Contexts.