このコレクション内のいずれかの行の主キーに、指定した値が格納されているかどうかを示す値を取得します。
Overloads Public Function Contains( _
ByVal key As Object _) As Boolean
[C#]
public bool Contains(objectkey);
[C++]
public: bool Contains(Object* key);
[JScript]
public function Contains(
key : Object) : Boolean;
パラメータ
- key
確認する主キーの値。
戻り値
指定した主キー値が格納されている DataRow がコレクション内にある場合は true 。それ以外の場合は false 。
例外
例外の種類 | 条件 |
---|---|
MissingPrimaryKeyException | このテーブルには主キーがありません。 |
解説
Contains メソッドを使用するには、 DataRowCollection オブジェクトが属する DataTable オブジェクトに、主キー列として指定された列が 1 つ以上格納されている必要があります。主キー列の作成の詳細については、 PrimaryKey プロパティのトピックを参照してください。
指定した値が行に格納されていると判断したら、 Find メソッドを使用して、その値が格納されている指定した DataRow オブジェクトを返すことができます。
使用例
[Visual Basic] Contains メソッドを使用して、 DataRowCollection オブジェクトに特定の値が格納されているかどうかを判断する例を次に示します。
Private Sub ColContains()
Dim myTable As DataTable
Dim rc As DataRowCollection
myTable = CType(DataGrid1.DataSource, DataTable)
rc = myTable.Rows
If rc.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
[C#, C++, JScript] C#、C++、および JScript のサンプルはありません。Visual Basic のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: 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
参照
DataRowCollection クラス | DataRowCollection メンバ | System.Data 名前空間 | DataRowCollection.Contains オーバーロードの一覧 | PrimaryKey | Find