IDbViewManager.GetViews Method

IIS 7.0

Retrieves a list of views in a database.

Namespace:  Microsoft.Web.Management.DatabaseManager
Assembly:  Microsoft.Web.Management.DatabaseManager (in Microsoft.Web.Management.DatabaseManager.dll)

ICollection<View> GetViews(
	string connectionString


Type: System.String
The connection string for the database.

Return Value

Type: System.Collections.Generic.ICollection<View>
An ICollection object that contains the list of View objects.

All database providers that implement the IDbViewManager interface must also implement the GetViews method, which the database manager will use to retrieve a list of views from a database.

Notes for Implementers

If your provider does not support retrieving the list of views, you can use the following code sample to raise a not-implemented exception:

public ICollection<View> GetViews(string connectionString)


   throw new NotImplementedException();


The following code sample implements the GetViews method to retrieve a list of views from a database in an OLEDB data source.

        // Retrieve the list of views from a database.
        public ICollection<View> GetViews(string connectionString)
            // Create a new list to hold the view information.
            List<View> views = new List<View>();
            // Create a new database connection.
            using (OleDbConnection connection = new OleDbConnection(connectionString))
                // Open the database connection.
                // Retrieve the schema information for the views.
                DataTable schema = connection.GetSchema(OleDbMetaDataCollectionNames.Views);
                // Loop through the collection of views.
                foreach (DataRow row in schema.Rows)
                    // Create a new view object.
                    View view = new View();
                    // Retrieve the name of the view.
                    view.Name = (string)row["TABLE_NAME"];
                    // Retrieve the table schema for the view.
                    view.Schema = (string)(row["TABLE_SCHEMA"] == DBNull.Value ? String.Empty : row["TABLE_SCHEMA"]);
                    // Retrieve the definition for the view.
                    view.Definition = (string)row["VIEW_DEFINITION"];
                    // Add the view to the list.
            // Return the list of views.
            return views;