|
1 | | ---- |
2 | | -title: "db_column | Microsoft Docs" |
3 | | -ms.custom: "" |
4 | | -ms.date: "11/04/2016" |
5 | | -ms.technology: ["cpp-windows"] |
6 | | -ms.topic: "reference" |
7 | | -f1_keywords: ["vc-attr.db_column"] |
8 | | -dev_langs: ["C++"] |
9 | | -helpviewer_keywords: ["db_column attribute"] |
10 | | -ms.assetid: 58da4afc-f69c-4ae6-af9a-3f9515f56081 |
11 | | -author: "mikeblome" |
12 | | -ms.author: "mblome" |
13 | | -ms.workload: ["cplusplus", "uwp"] |
14 | | ---- |
15 | | -# db_column |
16 | | -Binds a specified column to a variable in the rowset. |
17 | | - |
18 | | -## Syntax |
19 | | - |
20 | | -``` |
21 | | - |
22 | | - [ db_column( |
23 | | - ordinal, |
24 | | - dbtype, |
25 | | - precision, |
26 | | - scale, |
27 | | - status, |
28 | | - length |
29 | | -) ] |
30 | | -``` |
31 | | - |
32 | | -#### Parameters |
33 | | - `ordinal` |
34 | | - 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: |
35 | | - |
36 | | -``` |
37 | | -[db_column("2")] TCHAR szCity[30]; |
38 | | -[db_column(L"city_name")] TCHAR szCity[30]; |
39 | | -``` |
40 | | - |
41 | | - *dbtype* (optional) |
42 | | - An OLE DB [Type Indicator](https://msdn.microsoft.com/en-us/library/ms711251.aspx) for the column entry. |
43 | | - |
44 | | - *precision* (optional) |
45 | | - The precision to be used for the column entry. For details, see the description of the `bPrecision` element of the [DBBINDING structure](https://msdn.microsoft.com/en-us/library/ms716845.aspx) |
46 | | - |
47 | | - *scale* (optional) |
48 | | - The scale to be used for the column entry. For details, see the description of `bScale` element of the [DBBINDING structure](https://msdn.microsoft.com/en-us/library/ms716845.aspx) |
49 | | - |
50 | | - *status* (optional) |
51 | | - 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](https://msdn.microsoft.com/en-us/library/ms722617.aspx) in the *OLE DB Programmer's Reference*. |
52 | | - |
53 | | - *length* (optional) |
54 | | - A member variable used to hold the size of the column in bytes. |
55 | | - |
56 | | -## Remarks |
57 | | - **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](../data/oledb/begin-column-map.md), [END_COLUMN_MAP](../data/oledb/end-column-map.md), and [COLUMN_ENTRY](../data/oledb/column-entry.md). These manipulate the OLE DB [DBBINDING structure](https://msdn.microsoft.com/en-us/library/ms716845.aspx) 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. |
58 | | - |
59 | | - Use **db_column** in conjunction with either the [db_table](../windows/db-table.md) or [db_command](../windows/db-command.md) attributes. |
60 | | - |
61 | | - When the consumer attribute provider applies this attribute to a class, the compiler will rename the class to \_*YourClassName*Accessor, where *YourClassName* is the name you gave the class, and the compiler will also create a class called *YourClassName*, which derives from \_*YourClassName*Accessor. In Class View, you will see both classes. |
62 | | - |
63 | | - For examples of this attribute used in an application, see the samples [AtlAgent](http://msdn.microsoft.com/en-us/52bef5da-c1a0-4223-b4e6-9e464b6db409), and [MultiRead](http://msdn.microsoft.com/en-us/5a2a915a-77dc-492f-94b2-1b809995dd5e). |
64 | | - |
65 | | -## Example |
66 | | - This sample binds a column in a table to a **long** data member and specifies status and length fields. |
67 | | - |
68 | | -``` |
69 | | -// db_column_1.cpp |
70 | | -// compile with: /LD |
71 | | -#include <atlbase.h> |
72 | | -#include <atlplus.h> |
73 | | -#include <atldbcli.h> |
74 | | - |
75 | | -[ db_command(L"Select * from Products") ] |
76 | | -class CProducts { |
77 | | - DBSTATUS m_dwProductIDStatus; |
78 | | - DBLENGTH m_dwProductIDLength; |
79 | | - |
80 | | - [ db_column("1", status="m_dwProductIDStatus", length="m_dwProductIDLength") ] LONG m_ProductID; |
81 | | -}; |
82 | | -``` |
83 | | - |
84 | | -## Example |
85 | | - This sample binds four columns to a **long**, a character string, a timestamp, and a **DB_NUMERIC** integer, in that order. |
86 | | - |
87 | | -``` |
88 | | -// db_column_2.cpp |
89 | | -// compile with: /LD |
90 | | -#include <atlbase.h> |
91 | | -#include <atlplus.h> |
92 | | -#include <atldbcli.h> |
93 | | - |
94 | | -[ db_command(L"Select * from Products") ] |
95 | | -class CProducts { |
96 | | - [db_column("1")] LONG m_OrderID; |
97 | | - [db_column("2")] TCHAR m_CustomerID[6]; |
98 | | - [db_column("4")] DB_NUMERIC m_OrderDate; |
99 | | - [db_column("7", dbtype="DBTYPE_NUMERIC")] DB_NUMERIC m_ShipVia; |
100 | | -}; |
101 | | -``` |
102 | | - |
103 | | -## Requirements |
104 | | - |
105 | | -### Attribute Context |
106 | | - |
107 | | -||| |
108 | | -|-|-| |
109 | | -|**Applies to**|**class**, `struct`, member, method| |
110 | | -|**Repeatable**|No| |
111 | | -|**Required attributes**|None| |
112 | | -|**Invalid attributes**|None| |
113 | | - |
114 | | - For more information about the attribute contexts, see [Attribute Contexts](../windows/attribute-contexts.md). |
115 | | - |
116 | | -## See Also |
117 | | - [OLE DB Consumer Attributes](../windows/ole-db-consumer-attributes.md) |
118 | | - [Class Attributes](../windows/class-attributes.md) |
| 1 | +--- |
| 2 | +title: "db_column | Microsoft Docs" |
| 3 | +ms.custom: "" |
| 4 | +ms.date: "11/04/2016" |
| 5 | +ms.technology: ["cpp-windows"] |
| 6 | +ms.topic: "reference" |
| 7 | +f1_keywords: ["vc-attr.db_column"] |
| 8 | +dev_langs: ["C++"] |
| 9 | +helpviewer_keywords: ["db_column attribute"] |
| 10 | +ms.assetid: 58da4afc-f69c-4ae6-af9a-3f9515f56081 |
| 11 | +author: "mikeblome" |
| 12 | +ms.author: "mblome" |
| 13 | +ms.workload: ["cplusplus", "uwp"] |
| 14 | +--- |
| 15 | +# db_column |
| 16 | +Binds a specified column to a variable in the rowset. |
| 17 | + |
| 18 | +## Syntax |
| 19 | + |
| 20 | +``` |
| 21 | +[ db_column( |
| 22 | + ordinal, |
| 23 | + dbtype, |
| 24 | + precision, |
| 25 | + scale, |
| 26 | + status, |
| 27 | + length |
| 28 | +) ] |
| 29 | +``` |
| 30 | + |
| 31 | +#### Parameters |
| 32 | + `ordinal` |
| 33 | + 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: |
| 34 | + |
| 35 | +``` |
| 36 | +[db_column("2")] TCHAR szCity[30]; |
| 37 | +[db_column(L"city_name")] TCHAR szCity[30]; |
| 38 | +``` |
| 39 | + |
| 40 | + *dbtype* (optional) |
| 41 | + An OLE DB [Type Indicator](https://msdn.microsoft.com/en-us/library/ms711251.aspx) for the column entry. |
| 42 | + |
| 43 | + *precision* (optional) |
| 44 | + The precision to be used for the column entry. For details, see the description of the `bPrecision` element of the [DBBINDING structure](https://msdn.microsoft.com/en-us/library/ms716845.aspx) |
| 45 | + |
| 46 | + *scale* (optional) |
| 47 | + The scale to be used for the column entry. For details, see the description of `bScale` element of the [DBBINDING structure](https://msdn.microsoft.com/en-us/library/ms716845.aspx) |
| 48 | + |
| 49 | + *status* (optional) |
| 50 | + 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](https://msdn.microsoft.com/en-us/library/ms722617.aspx) in the *OLE DB Programmer's Reference*. |
| 51 | + |
| 52 | + *length* (optional) |
| 53 | + A member variable used to hold the size of the column in bytes. |
| 54 | + |
| 55 | +## Remarks |
| 56 | + **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](../data/oledb/begin-column-map.md), [END_COLUMN_MAP](../data/oledb/end-column-map.md), and [COLUMN_ENTRY](../data/oledb/column-entry.md). These manipulate the OLE DB [DBBINDING structure](https://msdn.microsoft.com/en-us/library/ms716845.aspx) 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. |
| 57 | + |
| 58 | + Use **db_column** in conjunction with either the [db_table](../windows/db-table.md) or [db_command](../windows/db-command.md) attributes. |
| 59 | + |
| 60 | + When the consumer attribute provider applies this attribute to a class, the compiler will rename the class to \_*YourClassName*Accessor, where *YourClassName* is the name you gave the class, and the compiler will also create a class called *YourClassName*, which derives from \_*YourClassName*Accessor. In Class View, you will see both classes. |
| 61 | + |
| 62 | + For examples of this attribute used in an application, see the samples [AtlAgent](http://msdn.microsoft.com/en-us/52bef5da-c1a0-4223-b4e6-9e464b6db409), and [MultiRead](http://msdn.microsoft.com/en-us/5a2a915a-77dc-492f-94b2-1b809995dd5e). |
| 63 | + |
| 64 | +## Example |
| 65 | + This sample binds a column in a table to a **long** data member and specifies status and length fields. |
| 66 | + |
| 67 | +``` |
| 68 | +// db_column_1.cpp |
| 69 | +// compile with: /LD |
| 70 | +#include <atlbase.h> |
| 71 | +#include <atlplus.h> |
| 72 | +#include <atldbcli.h> |
| 73 | + |
| 74 | +[ db_command(L"Select * from Products") ] |
| 75 | +class CProducts { |
| 76 | + DBSTATUS m_dwProductIDStatus; |
| 77 | + DBLENGTH m_dwProductIDLength; |
| 78 | + |
| 79 | + [ db_column("1", status="m_dwProductIDStatus", length="m_dwProductIDLength") ] LONG m_ProductID; |
| 80 | +}; |
| 81 | +``` |
| 82 | + |
| 83 | +## Example |
| 84 | + This sample binds four columns to a **long**, a character string, a timestamp, and a **DB_NUMERIC** integer, in that order. |
| 85 | + |
| 86 | +``` |
| 87 | +// db_column_2.cpp |
| 88 | +// compile with: /LD |
| 89 | +#include <atlbase.h> |
| 90 | +#include <atlplus.h> |
| 91 | +#include <atldbcli.h> |
| 92 | + |
| 93 | +[ db_command(L"Select * from Products") ] |
| 94 | +class CProducts { |
| 95 | + [db_column("1")] LONG m_OrderID; |
| 96 | + [db_column("2")] TCHAR m_CustomerID[6]; |
| 97 | + [db_column("4")] DB_NUMERIC m_OrderDate; |
| 98 | + [db_column("7", dbtype="DBTYPE_NUMERIC")] DB_NUMERIC m_ShipVia; |
| 99 | +}; |
| 100 | +``` |
| 101 | + |
| 102 | +## Requirements |
| 103 | + |
| 104 | +### Attribute Context |
| 105 | + |
| 106 | +||| |
| 107 | +|-|-| |
| 108 | +|**Applies to**|**class**, `struct`, member, method| |
| 109 | +|**Repeatable**|No| |
| 110 | +|**Required attributes**|None| |
| 111 | +|**Invalid attributes**|None| |
| 112 | + |
| 113 | + For more information about the attribute contexts, see [Attribute Contexts](../windows/attribute-contexts.md). |
| 114 | + |
| 115 | +## See Also |
| 116 | + [OLE DB Consumer Attributes](../windows/ole-db-consumer-attributes.md) |
| 117 | + [Class Attributes](../windows/class-attributes.md) |
0 commit comments