OnRemoveTable Method

DataSet.OnRemoveTable Method (DataTable)


Occurs when a DataTable is removed from a DataSet.

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

protected internal virtual void OnRemoveTable(
	DataTable table


Type: System.Data.DataTable

The DataTable being removed.

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

The following example shows a class derived from the DataSet with the OnRemoveTable method overridden.

public static void DemonstrateOnRemoveTable()
    DerivedDataSet dataSet = CreateDataSet();
    if(dataSet.Tables.Count > 0)

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

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

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

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

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

    return derived;

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft