Export (0) Print
Expand All

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
)

Parameters

connectionString
Type: System.String
The connection string for the database.
schema
Type: System.String
The schema name for the table.
Note   If schema is empty, the default schema name will be used.
tableInfo
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();
}
NoteNote:

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.
                connection.Open();
                // Begin a transaction.
                OleDbTransaction transaction = connection.BeginTransaction();
                try
                {
                    // 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.
                        command.ExecuteNonQuery();
                        // Commit the transaction.
                        transaction.Commit();
                    }
                }
                catch (Exception ex)
                {
                    // Roll back the transaction.
                    transaction.Rollback();
                    // Raise an exception if an error occurs.
                    throw new ProviderException("DROP TABLE Exception:\n\n" + ex.Message);
                }
                finally
                {
                    // Close the database connection.
                    connection.Close();
                }
            }
        }



Show:
© 2014 Microsoft