次の方法で共有


DataTableCollection.CanRemove メソッド

指定した DataTable オブジェクトをコレクションから削除できるかどうかを確認します。

Public Function CanRemove( _
   ByVal table As DataTable _) As Boolean
[C#]
public bool CanRemove(DataTabletable);
[C++]
public: bool CanRemove(DataTable* table);
[JScript]
public function CanRemove(
   table : DataTable) : Boolean;

パラメータ

  • table
    確認するコレクション内の DataTable

戻り値

このテーブルを削除できる場合は true 。それ以外の場合は false

使用例

[Visual Basic, C#, C++] CanRemove を使用して、各テーブルを DataSet から削除できるかどうかを確認する例を次に示します。削除できる場合は、テーブルを削除するために Remove メソッドが呼び出されます。

 
Private Sub RemoveTables()
   Dim t As DataTable
   Dim dSet As DataSet
   ' Presuming a DataGrid is displaying more than one table, get its DataSet.
   dSet = CType(DataGrid1.DataSource, DataSet)
   Do While dSet.Tables.Count > 0
      t = dSet.Tables(0)
      If dSet.Tables.CanRemove(t) Then
         dSet.Tables.Remove(t)
      End If
   Loop
End Sub

[C#] 
private void RemoveTables()
{
   DataTable t;
   DataSet dSet;
   // presuming a DataGrid is displaying more than one table, get its DataSet.
   dSet = (DataSet)DataGrid1.DataSource;
   while (dSet.Tables.Count > 0)
   {
      t = dSet.Tables[0];
      if (dSet.Tables.CanRemove(t))
         dSet.Tables.Remove(t);
   }
}

[C++] 
private:
 void RemoveTables()
 {
    DataTable* t;
    DataSet* dSet;
    // presuming a DataGrid is displaying more than one table, get its DataSet.
    dSet = dynamic_cast<DataSet*>(DataGrid1->DataSource);
    while (dSet->Tables->Count > 0)
    {
       t = dSet->Tables->Item[0];
       if (dSet->Tables->CanRemove(t))
          dSet->Tables->Remove(t);
    }
 }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

DataTableCollection クラス | DataTableCollection メンバ | System.Data 名前空間 | Item | IndexOf | Remove