Udostępnij za pośrednictwem


DBViewer Sample: Database Browser

The DBViewer sample is an enhancement of the MFC DAOVIEW sample. It demonstrates a mid-level application that relies on the OLE DB Templates CManualAccessor class. This sample illustrates how to take full control of the bindings and use them for your applications.

Security noteSecurity Note:

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

Building and Running the Sample

You can use DBViewer with the ODBC provider, and with the Microsoft Access 97 and Microsoft SQL Server 6.5 databases (or later versions). However, DBViewer cannot handle SQL Server stored procedures with integer parameters, or with names consisting of more than one word, for example, My stored procedure. You will get errors in these cases.

To build and run this sample

  1. Open the solution file DBViewer.sln.

  2. From the Build menu, click Build.

  3. From the Debug menu, click Start Without Debugging.

    A DBViewer dialog box will appear, with two panes.

  4. Click Open from the File menu. The Data Link Properties dialog box will appear. 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 a database such as Northwind.

    The specified database's tables and stored procedures will appear in the tree view pane on the left.

  5. Once you have connected to a data source, you can manipulate the data, call the stored procedures, and view the schema information. The tree view on the left side of the application window displays the tables and the stored procedures. To view or modify data, right-click a table or a stored procedure, and a shortcut menu will appear with additional operations.

How the Sample Works

Once DBViewer connects to a data source via the enumerator support, you can manipulate the data, call the stored procedures, and view the schema information. The tree view on the left side of the application window displays the tables and the stored procedures. To view or modify data, right-click a table or a stored procedure, and a shortcut menu will appear with additional operations.

This sample contains code to support stored procedures. However, you will find that not all stored procedures will run under this sample. This is because the underlying ODBC drivers do not provide support for some OLE DB methods. DBViewer does support multiple-result sets. If you click the list view where the data is located, you may see the multiple result sets button highlighted on the toolbar. You can click it and obtain the next result set.

DBViewer demonstrates how to use the error information in your application. The CErrorsDialog class handles the IErrorRecords interface and displays the error information returned from a particular call.

Note

Some of the samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

Keywords

The sample demonstrates the following classes:

CManualAccessor, CErrorsDialog

The sample demonstrates the following interfaces:

IErrorRecords

See Also

Other Resources

ATL Samples