Language

DataTableCollection.Contains メソッド

定義

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

オーバーロード

名前 説明
Contains(String)

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

Contains(String, String)

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

Contains(String)

ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs
ソース:
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 オブジェクトの名前を指定します。 DataTable メソッドを使用してコレクションにAddを追加し、引数を渡さない場合、テーブルは、テーブルが追加された順序 ("Table1"、"Table2"など) に基づいて既定の名前が指定されます。

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

Note

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

こちらもご覧ください

適用対象

Contains(String, String)

ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs
ソース:
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 オブジェクトの名前を指定します。 DataTable メソッドを使用してコレクションにAddを追加し、引数を渡さない場合、テーブルは、テーブルが追加された順序 ("Table1"、"Table2"など) に基づいて既定の名前が指定されます。

Note

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

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

こちらもご覧ください

適用対象