# 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.

# Building and Running the Sample

#### To build and run this sample

1. Open the solution file DynamicConsumer.sln.

2. From the Build menu, click Build.

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

4. 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.

5. 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.

6. 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