DataTableCollection.Contains メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した名前の DataTable オブジェクトがコレクションに存在するかどうかを示す値を取得します。
オーバーロード
| 名前 | 説明 |
|---|---|
| Contains(String) |
指定した名前の DataTable オブジェクトがコレクションに存在するかどうかを示す値を取得します。 |
| Contains(String, String) |
指定した名前とテーブル名前空間を持つ DataTable オブジェクトがコレクション内に存在するかどうかを示す値を取得します。 |
Contains(String)
指定した名前の 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
パラメーター
戻り値
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
注釈
TableName プロパティを使用して、DataTable オブジェクトの名前を指定します。 Add メソッドを使用してコレクションにDataTableを追加し、引数を渡さない場合、テーブルは、テーブルが追加された順序 ("Table1"、"Table2"など) に基づいて既定の名前が指定されます。
DataTableのインデックスを取得するには、IndexOf メソッドを使用します。
注
2 つ以上のテーブルの名前が同じで名前空間が異なる場合に false を返します。 テーブル名を 1 つのテーブルと完全に一致させるときにあいまいさがある場合、呼び出しは成功しません。
こちらもご覧ください
適用対象
Contains(String, String)
指定した名前とテーブル名前空間を持つ 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
パラメーター
戻り値
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
注釈
TableName プロパティを使用して、DataTable オブジェクトの名前を指定します。 Add メソッドを使用してコレクションにDataTableを追加し、引数を渡さない場合、テーブルは、テーブルが追加された順序 ("Table1"、"Table2"など) に基づいて既定の名前が指定されます。
注
2 つ以上のテーブルの名前が同じで名前空間が異なる場合に false を返します。 テーブル名を 1 つのテーブルと完全に一致させるときにあいまいさがある場合、呼び出しは成功しません。
DataTableのインデックスを取得するには、IndexOf メソッドを使用します。