DynamicConsumer Sample: Uses Dynamic Accessor and Schema Rowset Classes to Read Metadata from a Database
The DynamicConsumer sample is a simple console application that allows you to connect to any data source and select a table or stored procedure. If you select a stored procedure, the sample application will prompt you to enter the values for parameters. It then executes a command to display the data in the result rowset.
Security 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
To build and run this sample
Open the solution file DynamicConsumer.sln.
From the Build menu, click Build.
From the Debug menu, click Start Without Debugging.
A console window will appear, prompting you to specify which kind of accessor to use. Enter a number to specify an accessor type. Other specification menus will follow, depending on your choice.
When you are finished with the menu selections, the Data Link Properties dialog box will appear. On the Provider tab, select Microsoft OLE DB Provider for SQL Server. On the Connection tab, select a database such as Northwind.
When you have selected a data source, the console prompts you to specify the table from which you want to print out data. When you do so, the table's data displays in the console.
How the Sample Works
The sample uses schema rowset classes to read metadata from the data source. Metadata is any information about a data source other than the data stored in the database, such as column names, column data types, table names, or stored procedures. DynamicConsumer uses the schema rowset classes CTables, CProcedures, and CProcedureParameters to select the table or procedure and to build a SQL command string dynamically. The sample also uses the following accessor classes:
CDynamicAccessor (demonstrates the various ways to handle BLOB data)
CDynamicStringAccessor
CXMLAccessor
CDynamicParameterAccessor
Keywords
The sample demonstrates the following classes:
CDynamicAccessor, CDynamicParameterAccessor, CDynamicStringAccessor, CProcedureParameters, CProcedures, CTables, CXMLAccessor