IDbTableManager..::.DropTable Method Home
.NET Framework Class Library
IDbTableManager..::.DropTable Method

Removes a table from the database.

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

'Usage

Dim instance As IDbTableManager
Dim connectionString As String
Dim schema As String
Dim tableInfo As TableInfo

instance.DropTable(connectionString, _
    schema, tableInfo)

'Declaration

Sub DropTable ( _
    connectionString As String, _
    schema As String, _
    tableInfo As TableInfo _
)

Parameters

connectionString
Type: System..::.String
The connection string for the database.
schema
Type: System..::.String
The schema name for the table.
NoteNote:

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

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.

Examples

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 Sub DropTable(ByVal connectionString As String, ByVal schema As String, ByVal tableInfo As Microsoft.Web.Management.DatabaseManager.TableInfo) Implements Microsoft.Web.Management.DatabaseManager.IDbTableManager.DropTable
        ' Create a connection to the database.
        Dim connection As OleDbConnection = New OleDbConnection(connectionString)
        ' Open the connection to the database.
        connection.Open()
        ' Begin a transaction.
        Dim transaction As OleDbTransaction = connection.BeginTransaction
        Try
            ' Create the DROP TABLE SQL statement.
            Dim dropStatement As String = String.Format("DROP TABLE {0}", EscapeName(tableInfo.Name))
            ' Create an OLEDB command object.
            Dim command As OleDbCommand = New OleDbCommand(dropStatement, connection)
            ' Specify the transaction.
            command.Transaction = transaction
            ' Run the SQL statement.
            command.ExecuteNonQuery()
            ' Commit the transaction.
            transaction.Commit()
        Catch ex As Exception
            ' Roll back the transaction.
            transaction.Rollback()
            ' Raise an exception if an error occurs.
            Throw New ProviderException(("DROP TABLE Exception:" + vbCrLf + vbCrLf + ex.Message))
        Finally
            ' Close the database connection.
            connection.Close()
        End Try
    End Sub



Permissions

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .
See Also

Reference

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View