Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataSet.OnRemoveTable Method

Occurs when a DataTable is removed from a DataSet.

[Visual Basic]
Protected Overridable Sub OnRemoveTable( _
   ByVal table As DataTable _
)
[C#]
protected virtual void OnRemoveTable(
 DataTable table
);
[C++]
protected: virtual void OnRemoveTable(
 DataTable* table
);
[JScript]
protected function OnRemoveTable(
   table : DataTable
);

Parameters

table
The DataTable being removed.

Remarks

This method can be overridden by subclasses to restrict tables from being removed.

Example

[Visual Basic, C#, C++] The following example shows a class derived from the DataSet with the OnRemoveTable method overridden.

[Visual Basic] 

Public Shared Sub DemonstrateOnRemoveTable()
    Dim ds As DerivedDataSet = CreateDataSet()
    If ds.Tables.Count > 0 Then ds.Tables.RemoveAt( 0 )
End Sub

Public Class DerivedDataSet
    Inherits DataSet
    Protected Overrides Sub OnRemoveTable( table As DataTable )
        Console.WriteLine( "The '{0}' DataTable has been removed from the DataSet", _
            table.TableName )
    End Sub
End Class

Public Shared Function CreateDataSet() As DerivedDataSet
    ' Create a DataSet with one table containing two columns.
    Dim dds As DerivedDataSet = New DerivedDataSet()

    ' Add table to DataSet.
    Dim t As DataTable = dds.Tables.Add("Items")

    ' Add two columns.
    Dim c As DataColumn = t.Columns.Add( "id", Type.GetType("System.Int32") )
    c.AutoIncrement = True
    t.Columns.Add( "item", Type.GetType("System.Int32") )

    ' set primary key
    t.PrimaryKey = New DataColumn() { t.Columns("id") }

    return dds
End Function

[C#] 

public static void DemonstrateOnRemoveTable()
{
    DerivedDataSet ds = CreateDataSet();
    if( ds.Tables.Count > 0 )
        ds.Tables.RemoveAt( 0 );
}

public class DerivedDataSet: DataSet
{
    protected override void OnRemoveTable( DataTable table )
    {
        Console.WriteLine( "The '{0}' DataTable has been removed from the DataSet", 
            table.TableName );
    }
}

public static DerivedDataSet CreateDataSet()
{
    // Create a DataSet with one table containing two columns.
    DerivedDataSet dds = new DerivedDataSet();

    // Add table to DataSet.
    DataTable t = dds.Tables.Add("Items");

    // Add two columns.
    DataColumn c = t.Columns.Add( "id", typeof(int) );
    c.AutoIncrement = true;
    t.Columns.Add( "item", typeof(int) );

    // set primary key
    t.PrimaryKey = new DataColumn[] { t.Columns["id"] };

    return dds;
}

[C++] 
public:
    static void DemonstrateOnRemoveTable()
    {
        DerivedDataSet* ds = CreateDataSet();
        if (ds->Tables->Count > 0)
            ds->Tables->RemoveAt(0);
    };

    static DerivedDataSet* CreateDataSet()
    {
        // Create a DataSet with one table containing two columns.
        DerivedDataSet* dds = new DerivedDataSet();

        // Add table to DataSet.
        DataTable* t = dds->Tables->Add(S"Items");

        // Add two columns.
        DataColumn* c = t->Columns->Add(S"id", __typeof(int));
        c->AutoIncrement = true;
        t->Columns->Add(S"item", __typeof(int));

        // set primary key* t.PrimaryKey = new DataColumn*[] { t.Columns->Item[S"id"] };

        return dds;
    };

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataSet Class | DataSet Members | System.Data Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft