次の方法で共有


DataRowCollection.Find メソッド

指定した DataRow を取得します。

オーバーロードの一覧

主キー値で指定した行を取得します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Function Find(Object) As DataRow

[C#] public DataRow Find(object);

[C++] public: DataRow* Find(Object*);

[JScript] public function Find(Object) : DataRow;

指定した主キー値が格納されている行を取得します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Function Find(Object()) As DataRow

[C#] public DataRow Find(object[]);

[C++] public: DataRow* Find(Object*[]);

[JScript] public function Find(Object[]) : DataRow;

使用例

[Visual Basic, C#, C++] 配列の値を使用して、 DataRow オブジェクトのコレクション内の特定の行を検索する例を次に示します。このメソッドでは、 DataTable に 3 つの主キー列が格納されていると仮定されています。値の配列が作成されると、 Find メソッドがその配列で使用されて、特定の必要なオブジェクトが取得されます。

[Visual Basic, C#, C++] メモ   ここでは、Find のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Private Sub FindInMultiPKey(ByVal myTable As DataTable)
   Dim foundRow As DataRow
   ' Create an array for the key values to find.
   Dim findTheseVals(2) As Object
   ' Set the values of the keys to find.
   findTheseVals(0) = "John"
   findTheseVals(1) = "Smith"
   findTheseVals(2) = "5 Main St."
   foundRow = myTable.Rows.Find(findTheseVals)
   ' Display column 1 of the found row.
   If Not (foundRow Is Nothing) Then
     Console.WriteLine(foundRow(1).ToString())
   End If
End Sub

[C#] 
private void FindInMultiPKey(DataTable myTable){
    DataRow foundRow;
    // Create an array for the key values to find.
    object[]findTheseVals = new object[3];
    // Set the values of the keys to find.
    findTheseVals[0] = "John";
    findTheseVals[1] = "Smith";
    findTheseVals[2] = "5 Main St.";
    foundRow = myTable.Rows.Find(findTheseVals);
    // Display column 1 of the found row.
    if(foundRow != null)
      Console.WriteLine(foundRow[1]);
 }

[C++] 
private:
void FindInMultiPKey(DataTable* myTable){
    DataRow* foundRow;
    // Create an array for the key values to find.
    Object* findTheseVals[] = new Object*[3];
    // Set the values of the keys to find.
    findTheseVals[0] = S"John";
    findTheseVals[1] = S"Smith";
    findTheseVals[2] = S"5 Main St.";
    foundRow = myTable->Rows->Find(findTheseVals);
    // Display column 1 of the found row.
    if(foundRow != 0)
      Console::WriteLine(foundRow->Item[1]);
 }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

DataRowCollection クラス | DataRowCollection メンバ | System.Data 名前空間