DataTableCollection.Contains メソッド

定義

指定した名前の DataTable オブジェクトがコレクション内に存在するかどうかを示す値を取得します。

オーバーロード

Contains(String)

指定した名前の DataTable オブジェクトがコレクション内に存在するかどうかを示す値を取得します。

Contains(String, String)

指定した名前の DataTable オブジェクト、およびテーブルの名前空間がコレクション内に存在するかどうかを示す値を取得します。

Contains(String)

ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs

指定した名前の DataTable オブジェクトがコレクション内に存在するかどうかを示す値を取得します。

public:
 bool Contains(System::String ^ name);
public bool Contains (string? name);
public bool Contains (string name);
member this.Contains : string -> bool
Public Function Contains (name As String) As Boolean

パラメーター

name
String

検索する DataTable の名前です。

戻り値

指定したテーブルが存在する場合は true。それ以外の場合は false

次の例では、"Suppliers" という名前のテーブルが に存在するかどうかをテストします DataTableCollection

private void TestForTableName()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tablesCol = thisDataSet.Tables;

    // Check if the named table exists.
    if (tablesCol.Contains("Suppliers"))
        Console.WriteLine("Table named Suppliers exists");
}
Private Sub TestForTableName()
   ' Get the DataSet of a DataGrid.
   Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

   ' Get the DataTableCollection through the Tables property.
   Dim tablesCol As DataTableCollection = thisDataSet.Tables

   ' Check if the named table exists.
   If tablesCol.Contains("Suppliers") Then 
      Console.WriteLine("Table named Suppliers exists")
   End If
End Sub

注釈

オブジェクトの名前は、 DataTable プロパティを使用 TableName して指定します。 メソッドを使用Addして コレクションに を追加DataTableし、引数を渡さない場合、テーブルには、テーブルが追加された順序 ("Table1"、"Table2" など) に基づいて既定の名前が付けられます。

DataTableインデックスを取得するには、 メソッドを使用します IndexOf

Note

2 つ以上の false テーブルの名前は同じですが、名前空間が異なる場合は を返します。 1 つのテーブル名を正確に 1 つのテーブルに一致させるときにあいまいな点があると、この呼び出しは成功しません。

こちらもご覧ください

適用対象

Contains(String, String)

ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs

指定した名前の DataTable オブジェクト、およびテーブルの名前空間がコレクション内に存在するかどうかを示す値を取得します。

public:
 bool Contains(System::String ^ name, System::String ^ tableNamespace);
public bool Contains (string name, string tableNamespace);
member this.Contains : string * string -> bool
Public Function Contains (name As String, tableNamespace As String) As Boolean

パラメーター

name
String

検索する DataTable の名前です。

tableNamespace
String

検索する DataTable 名前空間の名前。

戻り値

指定したテーブルが存在する場合は true。それ以外の場合は false

次の例では、"Suppliers" という名前のテーブルが に存在するかどうかをテストします DataTableCollection

private void TestForTableName()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tablesCol = thisDataSet.Tables;

    // Check if the named table exists.
    if (tablesCol.Contains("Suppliers"))
        Console.WriteLine("Table named Suppliers exists");
}
Private Sub TestForTableName()
   ' Get the DataSet of a DataGrid.
   Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

   ' Get the DataTableCollection through the Tables property.
   Dim tablesCol As DataTableCollection = thisDataSet.Tables

   ' Check if the named table exists.
   If tablesCol.Contains("Suppliers") Then 
      Console.WriteLine("Table named Suppliers exists")
   End If
End Sub

注釈

オブジェクトの名前は、 DataTable プロパティを使用 TableName して指定します。 メソッドを使用Addして コレクションに を追加DataTableし、引数を渡さない場合、テーブルには、テーブルが追加された順序 ("Table1"、"Table2" など) に基づいて既定の名前が付けられます。

Note

2 つ以上の false テーブルの名前は同じですが、名前空間が異なる場合は を返します。 1 つのテーブル名を正確に 1 つのテーブルに一致させるときにあいまいな点があると、この呼び出しは成功しません。

DataTableインデックスを取得するには、 メソッドを使用します IndexOf

こちらもご覧ください

適用対象