IDbViewManager.EditView Method

IIS 7.0

Modifies the definition of a view in the database.

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

void EditView(
	string connectionString,
	string schema,
	View view
)

Parameters

connectionString
Type: System.String
The connection string for the database.
schema
Type: System.String
The schema name for the view.
Note   If schema is empty, the default schema name will be used.
view
Type: Microsoft.Web.Management.DatabaseManager.View
The View object for the view to edit.

All database providers that implement the IDbViewManager interface must also implement the EditView method, which the database manager will use to modify a view in a database.

Notes for Implementers

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

public void EditView(string connectionString, string schema, View view)

{

   throw new NotImplementedException();

}

NoteNote:

See the ALTER VIEW (Transact-SQL) topic for more information about the ALTER VIEW SQL statement.

The following code sample implements the EditView method to modify a view in a database in an OLEDB data source.



        public void EditView(string connectionString, string schema, View view)
        {
            // Create a new database connection.
            using (OleDbConnection connection = new OleDbConnection(connectionString))
            {
                // Create the SQL for the CREATE VIEW statement.
                string dropView = String.Format("DROP VIEW {0}", EscapeName(view.Name));
                // Create the SQL for the CREATE VIEW statement.
                string createView = String.Format("CREATE VIEW {0} AS {1}", EscapeName(view.Name), view.Definition);
                // Create a transaction.
                OleDbTransaction transaction = null;

                try
                {
                    // Open the database connection.
                    connection.Open();
                    // Begin a transaction.
                    transaction = connection.BeginTransaction();

                    // Create an OLEDB command object.
                    using (OleDbCommand command = new OleDbCommand())
                    {
                        // Specify the connection for the command.
                        command.Connection = connection;
                        // Specify the transaction for the command.
                        command.Transaction = transaction;

                        // Specify the DROP VIEW syntax.
                        command.CommandText = dropView;
                        // Execute the SQL statement.
                        command.ExecuteNonQuery();

                        // Specify the CREATE VIEW syntax.
                        command.CommandText = createView;
                        // Execute the SQL statement.
                        command.ExecuteNonQuery();

                        // Commit the transaction.
                        transaction.Commit();
                    }
                }
                catch (Exception ex)
                {
                    // Roll back the transaction if en exception occurred
                    transaction.Rollback();
                    // Raise an exception when an error occured.
                    throw new ProviderException(ex.Message);
                }
                finally
                {
                    // Close the database connection.
                    connection.Close();
                }
            }
        }



Show: