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
# Changes You Might Make to the Default Code (MFC Data Access)
15
15
The [MFC Application Wizard](../mfc/reference/database-support-mfc-application-wizard.md) writes a recordset class for you that selects all records in a single table. You will often want to modify that behavior in one or more of the following ways:
16
16
17
-
- Set a filter or a sort order for the recordset. Do this in `OnInitialUpdate` after the recordset object is constructed but before its **Open** member function is called. For more information, see [Recordset: Filtering Records (ODBC)](../data/odbc/recordset-filtering-records-odbc.md) and [Recordset: Sorting Records (ODBC)](../data/odbc/recordset-sorting-records-odbc.md).
17
+
- Set a filter or a sort order for the recordset. Do this in `OnInitialUpdate` after the recordset object is constructed but before its `Open` member function is called. For more information, see [Recordset: Filtering Records (ODBC)](../data/odbc/recordset-filtering-records-odbc.md) and [Recordset: Sorting Records (ODBC)](../data/odbc/recordset-sorting-records-odbc.md).
18
18
19
19
- Parameterize the recordset. Specify the actual run-time parameter value after the filter. For more information, see [Recordset: Parameterizing a Recordset (ODBC)](../data/odbc/recordset-parameterizing-a-recordset-odbc.md)
# Command Handlers for Record Scrolling (MFC Data Access)
15
15
The [CRecordView](../mfc/reference/crecordview-class.md) class provides default command handling for the following standard commands:
16
16
17
-
-**ID_RECORD_MOVE_FIRST**
17
+
- ID_RECORD_MOVE_FIRST
18
18
19
-
-**ID_RECORD_MOVE_LAST**
19
+
- ID_RECORD_MOVE_LAST
20
20
21
-
-**ID_RECORD_MOVE_NEXT**
21
+
- ID_RECORD_MOVE_NEXT
22
22
23
-
-**ID_RECORD_MOVE_PREV**
23
+
- ID_RECORD_MOVE_PREV
24
24
25
25
The `OnMove` member function provides default command handling for all four commands, which move from record to record. As these commands are issued, RFX (or DFX) loads the new record into the recordset's fields and DDX moves the values into the record form's controls. For information about RFX, see [Record Field Exchange (RFX)](../data/odbc/record-field-exchange-rfx.md).
Copy file name to clipboardexpand all lines: docs/data/data-access-programming-mfc-atl.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ OLE DB is a low-level, high-performance API based on the COM specification, and
18
18
19
19
If your legacy application uses OLE DB or the higher-level ADO interface to connect to SQL Server, and you are not accessing linked servers, you should consider migrating to ODBC in the near future. If you do not require cross-platform portability or the latest SQL Server features, you can possibly use the Microsoft OLE DB Provider for ODBC (MSDASQL). MSDASQL allows applications that are built on OLE DB and ADO (which uses OLEDB internally) to access data sources through an ODBC driver. As with any translation layer, MSDASQL can impact database performace. You should test to determine whether the impact is signifant for your application. MSDASQL ships with the Windows operating system, and Windows Server 2008 & Windows Vista SP1 are the first Windows releases to include a 64-bit version of the technology.
20
20
21
-
The SQL Native Client component (SNAC), which packages OLE DB and ODBC drivers in a single DLL, is deprecated for ODBC applications. The SQL Server 2012 version of SNAC (SQLNCLI11.DLL) ships with SQL Server 2016 because other SQL Server components depend on it. However, new C++ applications that connect to SQL Server or Azure SQL Database via ODBC should use [the most recent ODBC driver](https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server). For more information, see [SQL Server Native Client Programming](/sql/relational-databases/native-client/sql-server-native-client-programming)
21
+
The SQL Native Client component (SNAC), which packages OLE DB and ODBC drivers in a single DLL, is deprecated for ODBC applications. The SQL Server 2012 version of SNAC (SQLNCLI11.DLL) ships with SQL Server 2016 because other SQL Server components depend on it. However, new C++ applications that connect to SQL Server or Azure SQL Database via ODBC should use [the most recent ODBC driver](https://docs.microsoft.com/sql/connect/odbc/download-odbc-driver-for-sql-server). For more information, see [SQL Server Native Client Programming](/sql/relational-databases/native-client/sql-server-native-client-programming)
22
22
23
23
If you use C++/CLI, you can continue to use ADO.NET as always. For more information, see [Data Access Using ADO.NET (C++/CLI)](../dotnet/data-access-using-adonet-cpp-cli.md), and [Accessing data in Visual Studio](/visualstudio/data-tools/accessing-data-in-visual-studio).
24
24
@@ -29,4 +29,4 @@ For more information about the history of data access technologies on Microsoft
29
29
## See Also
30
30
[Data Access](data-access-in-cpp.md)
31
31
[Microsoft Open Database Connectivity (ODBC)](https://docs.microsoft.com/sql/odbc/microsoft-open-database-connectivity-odbc)
-[ODBC Driver 13.1 for SQL Server released](https://blogs.technet.microsoft.com/dataplatforminsider/2016/08/03/odbc-driver-13-1-for-sql-server-released/) Microsoft ODBC Driver 13 for SQL Server should be used to create new applications or enhance existing applications that need to take advantage of new SQL Server 2016 features.
Copy file name to clipboardexpand all lines: docs/data/mfc-using-database-classes-with-documents-and-views.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -36,20 +36,20 @@ You can use the MFC database classes with or without the document/view architect
36
36
37
37
- If you are accessing a recordset in a local context, create a `CRecordset` object locally in member functions of the document or the view, as needed.
38
38
39
-
Declare a recordset object as a local variable in a function. Pass **NULL** to the constructor, which causes the framework to create and open a temporary `CDatabase` object for you. As an alternative, pass a pointer to a `CDatabase` object. Use the recordset within the function and let it be destroyed automatically when the function exits.
39
+
Declare a recordset object as a local variable in a function. Pass NULL to the constructor, which causes the framework to create and open a temporary `CDatabase` object for you. As an alternative, pass a pointer to a `CDatabase` object. Use the recordset within the function and let it be destroyed automatically when the function exits.
40
40
41
-
When you pass **NULL** to a recordset constructor, the framework uses information returned by the recordset's `GetDefaultConnect` member function to create a `CDatabase` object and open it. The wizards implement `GetDefaultConnect` for you.
41
+
When you pass NULL to a recordset constructor, the framework uses information returned by the recordset's `GetDefaultConnect` member function to create a `CDatabase` object and open it. The wizards implement `GetDefaultConnect` for you.
42
42
43
43
- If you are accessing a recordset during the lifetime of your document, embed one or more `CRecordset` objects in your document.
44
44
45
-
Construct the recordset objects either when you initialize the document or as needed. You might write a function that returns a pointer to the recordset if it already exists or constructs and opens the recordset if it does not exist yet. Close, delete, and recreate the recordset as needed, or call its **Requery** member function to refresh the records.
45
+
Construct the recordset objects either when you initialize the document or as needed. You might write a function that returns a pointer to the recordset if it already exists or constructs and opens the recordset if it does not exist yet. Close, delete, and recreate the recordset as needed, or call its `Requery` member function to refresh the records.
46
46
47
47
- If you are accessing a data source during the lifetime of your document, embed a `CDatabase` object or store a pointer to a `CDatabase` object in it.
48
48
49
-
The `CDatabase` object manages a connection to your data source. The object is constructed automatically during document construction, and you call its **Open** member function when you initialize the document. When you construct recordset objects in document member functions, you pass a pointer to the document's `CDatabase` object. This associates each recordset with its data source. The database object is usually destroyed when the document closes. The recordset objects are typically destroyed when they exit the scope of a function.
49
+
The `CDatabase` object manages a connection to your data source. The object is constructed automatically during document construction, and you call its `Open` member function when you initialize the document. When you construct recordset objects in document member functions, you pass a pointer to the document's `CDatabase` object. This associates each recordset with its data source. The database object is usually destroyed when the document closes. The recordset objects are typically destroyed when they exit the scope of a function.
50
50
51
51
## <aname="_core_other_factors"></a> Other Factors
52
-
Form-based applications often do not have any use for the framework's document serialization mechanism, so you might want to remove, disable, or replace the `New` and **Open** commands on the **File** menu. See the article [Serialization: Serialization vs. Database Input/Output](../mfc/serialization-serialization-vs-database-input-output.md).
52
+
Form-based applications often do not have any use for the framework's document serialization mechanism, so you might want to remove, disable, or replace the **New** and **Open** commands on the **File** menu. See the article [Serialization: Serialization vs. Database Input/Output](../mfc/serialization-serialization-vs-database-input-output.md).
53
53
54
54
You might also want to make use of the many user-interface possibilities that the framework can support. For example, you could use multiple `CRecordView` objects in a splitter window, open multiple recordsets in different multiple document interface (MDI) child windows, and so on.
Copy file name to clipboardexpand all lines: docs/data/mfc-using-database-classes-without-documents-and-views.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -38,9 +38,9 @@ Sometimes you might not want to use the framework's document/view architecture i
38
38
39
39
|Option|View|Document|
40
40
|------------|----------|--------------|
41
-
|**None**|Derived from `CView`.|Provides no database support. This is the default option.<br /><br /> If you select the **Document/view architecture support** option on the [Application Type, MFC Application Wizard](../mfc/reference/application-type-mfc-application-wizard.md) page, you get full document support including serialization and `New`, **Open**, **Save**, and **Save As** commands on the **File** menu. See [Applications with No Document](#_core_applications_with_no_document).|
41
+
|**None**|Derived from `CView`.|Provides no database support. This is the default option.<br /><br /> If you select the **Document/view architecture support** option on the [Application Type, MFC Application Wizard](../mfc/reference/application-type-mfc-application-wizard.md) page, you get full document support including serialization and **New**, **Open**, **Save**, and **Save As** commands on the **File** menu. See [Applications with No Document](#_core_applications_with_no_document).|
42
42
|**Header files only**|Derived from `CView`.|Provides the basic level of database support for your application.<br /><br /> Includes Afxdb.h. Adds link libraries, but does not create any database-specific classes. You can create recordsets later and use them to examine and update records.|
43
-
|**Database view without file support**|Derived from `CRecordView`|Provides document support but no serialization support. Document can store recordset and coordinate multiple views; does not support serialization or the `New`, **Open**, **Save**, and **Save As** commands. See [Applications with Minimal Documents](#_core_applications_with_minimal_documents). If you include a database view, you must specify the source of the data.<br /><br /> Includes database header files, link libraries, a record view, and a recordset. (Available only for applications with the **Document/view architecture support** option selected on the [Application Type, MFC Application Wizard](../mfc/reference/application-type-mfc-application-wizard.md) page.)|
43
+
|**Database view without file support**|Derived from `CRecordView`|Provides document support but no serialization support. Document can store recordset and coordinate multiple views; does not support serialization or the **New**, **Open**, **Save**, and **Save As** commands. See [Applications with Minimal Documents](#_core_applications_with_minimal_documents). If you include a database view, you must specify the source of the data.<br /><br /> Includes database header files, link libraries, a record view, and a recordset. (Available only for applications with the **Document/view architecture support** option selected on the [Application Type, MFC Application Wizard](../mfc/reference/application-type-mfc-application-wizard.md) page.)|
44
44
|**Database view with file support**|Derived from `CRecordView`|Provides full document support, including serialization and document-related **File** menu commands. Database applications typically operate on a per-record basis rather than on a per-file basis and so do not need serialization. However, you might have a special use for serialization. See [Applications with Minimal Documents](#_core_applications_with_minimal_documents). If you include a database view, you must specify the source of the data.<br /><br /> Includes database header files, link libraries, a record view, and a recordset. (Available only for applications with the **Document/view architecture support** option selected on the [Application Type, MFC Application Wizard](../mfc/reference/application-type-mfc-application-wizard.md) page.)|
45
45
46
46
For a discussion of alternatives to serialization and alternative uses for serialization, see [Serialization: Serialization vs. Database Input/Output](../mfc/serialization-serialization-vs-database-input-output.md).
@@ -75,7 +75,7 @@ Sometimes you might not want to use the framework's document/view architecture i
75
75
### <aname="_core_writing_applications_without_documents"></a> Writing Applications Without Documents
76
76
Because the application wizard does not support creating applications without documents, you must write your own `CWinApp`-derived class and, if needed, also create a `CFrameWnd` or `CMDIFrameWnd` class. Override `CWinApp::InitInstance` and declare an application object as:
77
77
78
-
```
78
+
```cpp
79
79
CYourNameApp theApp;
80
80
```
81
81
@@ -90,7 +90,7 @@ CYourNameApp theApp;
90
90
91
91
Because no document owns the `CRecordset` object, you probably want to store it as an embedded data member in your `CWinApp`-derived application class. Alternatives include:
92
92
93
-
- Not keeping a permanent `CRecordset` object at all. You can pass **NULL** to your recordset class constructors. In that case, the framework creates a temporary `CDatabase` object using the information in the recordset's `GetDefaultConnect` member function. This is the most likely alternative approach.
93
+
- Not keeping a permanent `CRecordset` object at all. You can pass NULL to your recordset class constructors. In that case, the framework creates a temporary `CDatabase` object using the information in the recordset's `GetDefaultConnect` member function. This is the most likely alternative approach.
94
94
95
95
- Making the `CRecordset` object a global variable. This variable should be a pointer to a recordset object that you create dynamically in your `CWinApp::InitInstance` override. This avoids attempting to construct the object before the framework is initialized.
Copy file name to clipboardexpand all lines: docs/data/odbc/odbc-calling-odbc-api-functions-directly.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ The database classes provide a simpler interface to a [data source](../../data/o
29
29
30
30
- Deallocate storage when you finish.
31
31
32
-
For more information about these steps, see the [Open Database Connectivity (ODBC)](https://msdn.microsoft.com/en-us/library/ms710252.aspx) SDK in the MSDN documentation.
32
+
For more information about these steps, see the [Open Database Connectivity (ODBC)](https://msdn.microsoft.com/library/ms710252.aspx) SDK in the MSDN documentation.
33
33
34
34
In addition to these steps, you need to take extra steps to check function return values, ensure that your program is not waiting for an asynchronous call to finish, and so on. You can simplify these last steps by using the AFX_SQL_ASYNC and AFX_SQL_SYNC macros. For more information, see [Macros and Globals](../../mfc/reference/mfc-macros-and-globals.md) in the *MFC Reference*.
In the MFC ODBC database classes, dynasets are recordsets with dynamic properties; they remain synchronized with the data source in certain ways. MFC dynasets (but not forward-only recordsets) require an ODBC driver with Level 2 API conformance. If the driver for your [data source](../../data/odbc/data-source-odbc.md) conforms to the Level 1 API set, you can still use both updateable and read-only snapshots and forward-only recordsets, but not dynasets. However, a Level 1 driver can support dynasets if it supports extended fetch and keyset-driven cursors.
16
16
17
-
In ODBC terminology, dynasets and snapshots are referred to as cursors. A cursor is a mechanism used for keeping track of its position in a recordset. For more information about driver requirements for dynasets, see [Dynaset](../../data/odbc/dynaset.md). For more information about cursors, see the [Open Database Connectivity (ODBC)](https://msdn.microsoft.com/en-us/library/ms710252.aspx) SDK in the MSDN documentation.
17
+
In ODBC terminology, dynasets and snapshots are referred to as cursors. A cursor is a mechanism used for keeping track of its position in a recordset. For more information about driver requirements for dynasets, see [Dynaset](../../data/odbc/dynaset.md). For more information about cursors, see the [Open Database Connectivity (ODBC)](https://msdn.microsoft.com/library/ms710252.aspx) SDK in the MSDN documentation.
18
18
19
19
> [!NOTE]
20
20
> For updateable recordsets, your ODBC driver must support either positioned update statements or the `::SQLSetPos` ODBC API function. If both are supported, MFC uses `::SQLSetPos` for efficiency. Alternatively, for snapshots, you can use the cursor library, which provides the required support for updateable snapshots (static cursors and positioned update statements).
0 commit comments