You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After you open the data source, session, and rowset objects, you can fetch data. Depending on the type of accessor you are using, you might need to bind columns.
17
-
18
-
### To fetch data
19
-
20
-
1. Open the rowset using the appropriate **Open** command.
21
-
22
-
1. If you are using `CManualAccessor`, bind the output columns if you have not already done so. To bind the columns, call `GetColumnInfo`, and then create an accessor with the bindings, as shown in the following example:
23
-
24
-
```cpp
25
-
// From the DBViewer Sample CDBTreeView::OnQueryEdit
26
-
// Get the column information
27
-
ULONG ulColumns = 0;
28
-
DBCOLUMNINFO* pColumnInfo = NULL;
29
-
LPOLESTR pStrings = NULL;
30
-
if (rs.GetColumnInfo(&ulColumns, &pColumnInfo, &pStrings) != S_OK)
1. Write a `while` loop to retrieve the data. In the loop, call `MoveNext` to advance the cursor and test the return value against S_OK, as shown in the following example:
40
-
41
-
```cpp
42
-
while (rs.MoveNext() == S_OK)
43
-
{
44
-
// Add code to fetch data here
45
-
// If you are not using an auto accessor, call rs.GetData()
46
-
}
47
-
```
48
-
49
-
1. Within the `while` loop, you can fetch the data according to your accessor type.
50
-
51
-
- If you use the [CAccessor](../../data/oledb/caccessor-class.md) class, you should have a user record that contains data members. You can access your data using those data members, as shown in the following example:
52
-
53
-
```cpp
54
-
while (rs.MoveNext() == S_OK)
55
-
{
56
-
// Use the data members directly. In this case, m_nFooID
57
-
// is declared in a user record that derives from
58
-
// CAccessor
59
-
wsprintf_s("%d", rs.m_nFooID);
60
-
}
61
-
```
62
-
63
-
- If you use the `CDynamicAccessor` or `CDynamicParameterAccessor` class, you can fetch data by using the accessing functions `GetValue` and `GetColumn`, as shown in the following example. If you want to determine the type of data you are using, use `GetType`.
64
-
65
-
```cpp
66
-
while (rs.MoveNext() == S_OK)
67
-
{
68
-
// Use the dynamic accessor functions to retrieve your data.
69
-
70
-
ULONG ulColumns = rs.GetColumnCount();
71
-
for (ULONG i=0; i<ulColumns; i++)
72
-
{
73
-
rs.GetValue(i);
74
-
}
75
-
}
76
-
```
77
-
78
-
- If you use `CManualAccessor`, you must specify your own data members, bind them yourself, and access them directly, as shown in the following example:
79
-
80
-
```cpp
81
-
while (rs.MoveNext() == S_OK)
82
-
{
83
-
// Use the data members you specified in the calls to
84
-
// AddBindEntry.
85
-
86
-
wsprintf_s("%s", szFoo);
87
-
}
88
-
```
89
-
90
-
## See Also
91
-
92
-
[Working with OLE DB Consumer Templates](../../data/oledb/working-with-ole-db-consumer-templates.md)
16
+
After you open the data source, session, and rowset objects, you can fetch data. Depending on the type of accessor you are using, you might need to bind columns.
17
+
18
+
### To fetch data
19
+
20
+
1. Open the rowset using the appropriate **Open** command.
21
+
22
+
1. If you are using `CManualAccessor`, bind the output columns if you have not already done so. To bind the columns, call `GetColumnInfo`, and then create an accessor with the bindings, as shown in the following example:
23
+
24
+
```cpp
25
+
// From the DBViewer Sample CDBTreeView::OnQueryEdit
26
+
// Get the column information
27
+
ULONG ulColumns = 0;
28
+
DBCOLUMNINFO* pColumnInfo = NULL;
29
+
LPOLESTR pStrings = NULL;
30
+
if (rs.GetColumnInfo(&ulColumns, &pColumnInfo, &pStrings) != S_OK)
1. Write a `while` loop to retrieve the data. In the loop, call `MoveNext` to advance the cursor and test the return value against S_OK, as shown in the following example:
40
+
41
+
```cpp
42
+
while (rs.MoveNext() == S_OK)
43
+
{
44
+
// Add code to fetch data here
45
+
// If you are not using an auto accessor, call rs.GetData()
46
+
}
47
+
```
48
+
49
+
1. Within the `while` loop, you can fetch the data according to your accessor type.
50
+
51
+
- If you use the [CAccessor](../../data/oledb/caccessor-class.md) class, you should have a user record that contains data members. You can access your data using those data members, as shown in the following example:
52
+
53
+
```cpp
54
+
while (rs.MoveNext() == S_OK)
55
+
{
56
+
// Use the data members directly. In this case, m_nFooID
57
+
// is declared in a user record that derives from
58
+
// CAccessor
59
+
wsprintf_s("%d", rs.m_nFooID);
60
+
}
61
+
```
62
+
63
+
- If you use the `CDynamicAccessor` or `CDynamicParameterAccessor` class, you can fetch data by using the accessing functions `GetValue` and `GetColumn`, as shown in the following example. If you want to determine the type of data you are using, use `GetType`.
64
+
65
+
```cpp
66
+
while (rs.MoveNext() == S_OK)
67
+
{
68
+
// Use the dynamic accessor functions to retrieve your data.
69
+
70
+
ULONG ulColumns = rs.GetColumnCount();
71
+
for (ULONG i=0; i<ulColumns; i++)
72
+
{
73
+
rs.GetValue(i);
74
+
}
75
+
}
76
+
```
77
+
78
+
- If you use `CManualAccessor`, you must specify your own data members, bind them yourself, and access them directly, as shown in the following example:
79
+
80
+
```cpp
81
+
while (rs.MoveNext() == S_OK)
82
+
{
83
+
// Use the data members you specified in the calls to
84
+
// AddBindEntry.
85
+
86
+
wsprintf_s("%s", szFoo);
87
+
}
88
+
```
89
+
90
+
## See Also
91
+
92
+
[Working with OLE DB Consumer Templates](../../data/oledb/working-with-ole-db-consumer-templates.md)
0 commit comments