Language

DataRowCollection.Contains メソッド

定義

コレクション内の任意の行の主キー列に指定した値が含まれているかどうかを示す値を取得します。

オーバーロード

名前 説明
Contains(Object)

コレクション内の任意の行の主キーに指定した値が含まれているかどうかを示す値を取得します。

Contains(Object[])

コレクション内の任意の行の主キー列に、オブジェクト配列で指定された値が含まれているかどうかを示す値を取得します。

Contains(Object)

ソース:
DataRowCollection.cs
ソース:
DataRowCollection.cs
ソース:
DataRowCollection.cs
ソース:
DataRowCollection.cs
ソース:
DataRowCollection.cs

コレクション内の任意の行の主キーに指定した値が含まれているかどうかを示す値を取得します。

public:
 bool Contains(System::Object ^ key);
public bool Contains(object? key);
public bool Contains(object key);
member this.Contains : obj -> bool
Public Function Contains (key As Object) As Boolean

パラメーター

key
Object

テスト対象の主キーの値。

返品

true 指定した主キー値を持つ DataRow がコレクションに含まれている場合は。それ以外の場合は false。

例外

テーブルに主キーがありません。

例

次の Visual Basic の例では、 Contains メソッドを使用して、 DataRowCollection オブジェクトに特定の値が含まれているかどうかを判断します。

 Private Sub ColContains()
    Dim table As DataTable = CType(DataGrid1.DataSource, DataTable)
    Dim rowCollection As DataRowCollection = table.Rows
    If rowCollection.Contains(Edit1.Text) Then
       Label1.Text = "At least one row contains " & Edit1.Text 
    Else
       Label1.Text = "No row contains the value in its primary key field"
    End If
End Sub

注釈

Contains メソッドを使用するには、DataTable オブジェクトが属するDataRowCollection オブジェクトに、主キー列として指定された列が少なくとも 1 つ必要です。 主キー列を作成する方法の詳細については、 PrimaryKey プロパティを参照してください。

指定した値が行に含まれていると判断するとすぐに、 Find メソッドを使用して、値を持つ特定の DataRow オブジェクトを返すことができます。

こちらもご覧ください

適用対象

Contains(Object[])

ソース:
DataRowCollection.cs
ソース:
DataRowCollection.cs
ソース:
DataRowCollection.cs
ソース:
DataRowCollection.cs
ソース:
DataRowCollection.cs

コレクション内の任意の行の主キー列に、オブジェクト配列で指定された値が含まれているかどうかを示す値を取得します。

public:
 bool Contains(cli::array <System::Object ^> ^ keys);
public bool Contains(object?[] keys);
public bool Contains(object[] keys);
member this.Contains : obj[] -> bool
Public Function Contains (keys As Object()) As Boolean

パラメーター

keys
Object[]

テスト対象の主キー値の配列。

返品

true指定したキー値を持つDataRowCollectionがDataRowに含まれている場合は。それ以外の場合はfalse。

例外

テーブルに主キーがありません。

例

次の Visual Basic の例では、 Contains メソッドを使用して、 DataRowCollection オブジェクト内の特定の行を検索します。 この例では、テーブル内の主キーごとに 1 つの要素である値の配列を作成し、その配列をメソッドに渡して、 true または falseを返します。

Private Sub ContainsArray()
   ' This example assumes that the DataTable object contains two
   ' DataColumn objects designated as primary keys.
   ' The table has two primary key columns.
   Dim arrKeyVals(1) As Object
   Dim table As DataTable = CType(DataGrid1.DataSource, DataTable)
   Dim rowCollection As DataRowCollection = table.Rows
   arrKeyVals(0) = "Hello"
   arrKeyVals(1) = "World"
   label1.Text = rowCollection.Contains(arrKeyVals).ToString()
End Sub

注釈

Containsメソッドを値の配列と共に使用するには、DataTable オブジェクトが属するDataRowCollection オブジェクトに、主キーとして指定された列の配列が必要です。 主キー列の配列を作成する方法の詳細については、 PrimaryKey プロパティを参照してください。 配列要素の数は、 DataTableの主キー列の数に対応している必要があります。

指定した値が行に含まれていると判断したらすぐに、 Find メソッドを使用して、値を持つ特定の DataRow オブジェクトを返します。

こちらもご覧ください

適用対象