IDbTableManager.DropTable Method

IIS 7.0

Removes a table from the database.

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

void DropTable(
	string connectionString,
	string schema,
	TableInfo tableInfo


Type: System.String
The connection string for the database.
Type: System.String
The schema name for the table.
Note   If schema is empty, the default schema name will be used.
Type: Microsoft.Web.Management.DatabaseManager.TableInfo
A TableInfo object that contains the list of information about the table and columns.

All database providers that implement the IDbTableManager interface must also implement the DropTable method, which the database manager will use to remove a table from a database.

Notes for Implementers

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

public void void DropTable(string connectionString, string schema, TableInfo tableInfo)
   throw new NotImplementedException();

See the DROP TABLE (Transact-SQL) topic for more information about the DROP TABLE SQL statements.

The following code sample shows how to use the DropTable method for an OLEDB connection by using the TableInfo object that the database manager provides.

        public void DropTable(string connectionString, string schema, TableInfo tableInfo)
            // Create a connection to the database.
            using (OleDbConnection connection = new OleDbConnection(connectionString))
                // Open the connection to the database.
                // Begin a transaction.
                OleDbTransaction transaction = connection.BeginTransaction();
                    // Create the DROP TABLE SQL statement.
                    string dropStatement = String.Format("DROP TABLE {0}", EscapeName(tableInfo.Name));
                    // Create an OLEDB command object.
                    using (OleDbCommand command = new OleDbCommand(dropStatement, connection))
                        // Specify the transaction.
                        command.Transaction = transaction;
                        // Run the SQL statement.
                        // Commit the transaction.
                catch (Exception ex)
                    // Roll back the transaction.
                    // Raise an exception if an error occurs.
                    throw new ProviderException("DROP TABLE Exception:\n\n" + ex.Message);
                    // Close the database connection.