The information in this article applies to:
SUMMARY
Microsoft Foundation Classes (MFC) version 2.5 and later use the Open
Database Connectivity (ODBC) API (application programming interface) to
access and manipulate data. Before a table can be created, ODBC requires
that a "data source" be configured to allow access to data. A data source
is a set of data that can be located in a variety of databases (for
example, FoxPro, Access, SQL Server, and so forth) in various locations
(for example, local or network). Once a data source is configured/named,
the programmer only needs to specify the name of the data source to connect
to the data. To create a table for the data source, use the
CDatabase::ExecuteSQL() function and pass it a string that uses the CREATE
TABLE SQL statement.
Q110507 HOWTO: Configure ODBC Data Sources on the FlyNOTE: The information contained within this article is duplicated in the 'Programming with MFC Encyclopedia' shipped with Visual C++ 4.0. The article can be found by searching for "SQLConfigDataSource" and selecting the article titled 'FAQ: Programatically Configuring an ODBC Data Source'. MORE INFORMATION
To create a data source, the ODBC Administrator program, which is normally
found in Windows Control Panel as an icon labeled "ODBC", is typically
used.
The code above creates a table called "OFFICES" in the ACCESS data source
connected to by myDB; the table contains two fields "OfficeID" and
"OfficeName".
NOTE: The field types specified in the CREATE TABLE SQL statement may vary according to the ODBC driver that you are using. For example, the Btrieve ODBC driver will require "STRING" in place of the "TEXT" type shown in the CREATE TABLE statement above. The MSQUERY program is one way to discover what field types are available for a data source. In MSQUERY, select File, choose Table_Definition, select a table from a data source, and look at the type shown in the "Type" combo box. REFERENCESFor more information about data sources, see the "Database Classes Encyclopedia" in the online books. Additional query words: 2.50 2.51 2.52 3.00 3.10
Keywords : kbprg kbDatabase kbMFC kbODBC kbVC |
Last Reviewed: July 23, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |