CatDB Sample: Data Source Schema Browser
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.
To get samples and instructions for installing them:
To access samples from Visual Studio
On the Help menu, click Samples.
By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.
- For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.
Building and Running the Sample
You can use this sample with the ODBC provider and with the Microsoft Access 97 and Microsoft SQL Server 6.5 databases (or later versions). To run this sample, you must have the MDAC SDK installed.
To build and run this sample
On the Build menu, click Build.
On the Debug menu, click Start Without Debugging.
The CatDB - [No data source selected] dialog box is displayed.
On the File menu, click Open to display the Data Link Properties dialog boxr. On the Provider tab, select Microsoft OLE DB Provider for SQL Server (or Microsoft Jet 4.0 OLE DB Provider). On the Connection tab, select the Northwind database.
The table information will appear in the dialog box. The dialog box title will change to the database name.
How the Sample Works
The code to enumerate the providers, connect to a data source, and create a session is in the CCatDBDoc::OnOpenDocument function. The code to open the schema rowsets is in CCatDBDoc::FetchTableInfo and CCatDBDoc::FetchColumnInfo. Both FetchTableInfo and FetchColumnInfo use the OLE DB Templates schema rowset classes, CTables, CTableInfo and CColumns, CColumnsInfo. The code to display the schema information is in CCatDBView::OnUpdate. The OnUpdatefunction moves through the records in the database and accesses the CTables and CColumns classes for data.
This sample may not exactly demonstrate some features of the Visual C++ wizards, libraries, and compiler, but it still shows how to complete the intended task.
The sample demonstrates the following classes:
CColumns, CDataSource, CSession, CTables
The sample demonstrates the following functions: