共用方式為


DataTableCollection.CanRemove(DataTable) 方法

定義

驗證是否可以從集合移除指定的 DataTable 物件。

public:
 bool CanRemove(System::Data::DataTable ^ table);
public bool CanRemove (System.Data.DataTable? table);
public bool CanRemove (System.Data.DataTable table);
member this.CanRemove : System.Data.DataTable -> bool
Public Function CanRemove (table As DataTable) As Boolean

參數

table
DataTable

集合中要執行檢查的 DataTable

傳回

如果可以將資料表移除,則為 true,否則為 false

範例

下列範例會使用 CanRemove 來測試是否可以從 DataSet中移除每個數據表。 如果是,則會 Remove 呼叫 方法來移除數據表。

private void RemoveTables()
{
    DataTable table;

    // presuming a DataGrid is displaying more than one table, get its DataSet.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;
    while (thisDataSet.Tables.Count > 0)
    {
        table = thisDataSet.Tables[0];
        if (thisDataSet.Tables.CanRemove(table))
            thisDataSet.Tables.Remove(table);
    }
}
Private Sub RemoveTables()
    ' Presuming a DataGrid is displaying more than one table, 
    ' get its DataSet.
    Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)
    Do While thisDataSet.Tables.Count > 0
       Dim table As DataTable = thisDataSet.Tables(0)
       If thisDataSet.Tables.CanRemove(table) Then
          thisDataSet.Tables.Remove(table)
       End If
    Loop
End Sub

適用於

另請參閱