次の方法で共有


DataRow.GetParentRow メソッド (DataRelation)

指定した DataRelation を使用して、 DataRow の親行を取得します。

Overloads Public Function GetParentRow( _
   ByVal relation As DataRelation _) As DataRow
[C#]
public DataRow GetParentRow(DataRelationrelation);
[C++]
public: DataRow* GetParentRow(DataRelation* relation);
[JScript]
public function GetParentRow(
   relation : DataRelation) : DataRow;

パラメータ

戻り値

現在の行の親 DataRow

例外

例外の種類 条件
ArgumentNullException この relationDataTable に属していません。

行が null 参照 (Visual Basic では Nothing) です。

InvalidConstraintException この行は DataRelation オブジェクトの子テーブルに属していません。
RowNotInTableException この行はテーブルに属していません。

解説

DataSet で、データ セットのすべての親 DataRelation オブジェクトのコレクションは、 GetParentRows メソッドによって返されます。

DataTable は、 ParentRelations プロパティが返す DataRelation オブジェクトのコレクションも格納します。

使用例

[Visual Basic, C#, C++] GetParentRow を使用して、 DataTable 内の各子 DataRelation の子 DataRow オブジェクトを返す例を次に示します。次に、行の各列の値が出力されます。

 
Private Sub GetParentRowForTable _
(thisTable As DataTable, relation As DataRelation)
    If thisTable Is Nothing Then
        Return
    End If
    ' For each row in the table, print column 1 of the parent DataRow.
    Dim parentRow As DataRow
    Dim r As DataRow
    For Each r In  thisTable.Rows
        parentRow = r.GetParentRow(relation)
        Console.Write(ControlChars.Tab + " child row: " + r(1).ToString())
        Console.Write(ControlChars.Tab + " parent row: " _
           + parentRow(1).ToString() + ControlChars.Cr)
    Next r
End Sub
  
Private Sub CallGetParentRowForTable()
    ' An example of calling the function.
    Dim thisTable As DataTable = DataSet1.Tables("Products")
    Dim relation As DataRelation = thisTable.ParentRelations(0)
    GetParentRowForTable(thisTable, relation)
End Sub

[C#] 
private void GetParentRowForTable(DataTable thisTable, DataRelation relation){
   if(thisTable ==null){return;}
   // For each row in the table, print column 1 of the parent DataRow.
   DataRow parentRow;
   foreach(DataRow r in thisTable.Rows){
      parentRow = r.GetParentRow(relation);
      Console.Write("\t child row: " + r[1]);
      Console.Write("\t parent row: " + parentRow[1]+ "\n");
   }
}

private void CallGetParentRowForTable(){
   // An example of calling the function.
   DataTable thisTable = DataSet1.Tables["Products"];
   DataRelation relation = thisTable.ParentRelations[0];
   GetParentRowForTable(thisTable, relation);
}

[C++] 
private:
 void GetParentRowForTable(DataTable* thisTable, DataRelation* relation){
    if(thisTable ==0){return;}
    // For each row in the table, print column 1 of the parent DataRow.
    DataRow* parentRow;
    System::Collections::IEnumerator* myEnum = thisTable->Rows->GetEnumerator();
    while (myEnum->MoveNext())
    {
       DataRow* r = __try_cast<DataRow*>(myEnum->Current);
       parentRow = r->GetParentRow(relation);
       Console::Write(S"\t child row: {0}", r->Item[1]);
       Console::Write(S"\t parent row: {0}\n", parentRow->Item[1]);
    }
 }
 
 void CallGetParentRowForTable(){
    // An example of calling the function.
    DataTable* thisTable = DataSet1->Tables->Item[S"Products"];
    DataRelation* relation = thisTable->ParentRelations->Item[0];
    GetParentRowForTable(thisTable, relation);
 }

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

必要条件

プラットフォーム: 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

参照

DataRow クラス | DataRow メンバ | System.Data 名前空間 | DataRow.GetParentRow オーバーロードの一覧 | ChildRelations | DataRelation | GetChildRows | GetParentRow | Relations