Skip to content

Commit da72614

Browse files
author
Colin Robertson
authored
Update fetching-data.md
- I'm practically sure of it.
1 parent 679c437 commit da72614

1 file changed

Lines changed: 77 additions & 77 deletions

File tree

docs/data/oledb/fetching-data.md

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -13,80 +13,80 @@ ms.workload: ["cplusplus", "data-storage"]
1313
---
1414
# Fetching Data
1515

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)
31-
ThrowMyOLEDBException(rs.m_pRowset, IID_IColumnsInfo);
32-
struct MYBIND* pBind = new MYBIND[ulColumns];
33-
rs.CreateAccessor(ulColumns, &pBind[0], sizeof(MYBIND)*ulColumns);
34-
for (ULONG l=0; l<ulColumns; l++)
35-
rs.AddBindEntry(l+1, DBTYPE_STR, sizeof(TCHAR)*40, &pBind[l].szValue, NULL, &pBind[l].dwStatus);
36-
rs.Bind();
37-
```
38-
39-
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)
31+
ThrowMyOLEDBException(rs.m_pRowset, IID_IColumnsInfo);
32+
struct MYBIND* pBind = new MYBIND[ulColumns];
33+
rs.CreateAccessor(ulColumns, &pBind[0], sizeof(MYBIND)*ulColumns);
34+
for (ULONG l=0; l<ulColumns; l++)
35+
rs.AddBindEntry(l+1, DBTYPE_STR, sizeof(TCHAR)*40, &pBind[l].szValue, NULL, &pBind[l].dwStatus);
36+
rs.Bind();
37+
```
38+
39+
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

Comments
 (0)