次の方法で共有


DataRow.GetParentRow メソッド (String)

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

Overloads Public Function GetParentRow( _
   ByVal relationName As String _) As DataRow
[C#]
public DataRow GetParentRow(stringrelationName);
[C++]
public: DataRow* GetParentRow(String* relationName);
[JScript]
public function GetParentRow(
   relationName : String) : DataRow;

パラメータ

戻り値

現在の行の親 DataRow

例外

例外の種類 条件
ArgumentException リレーションシップと行が同じテーブルに属していません。
RowNotInTableException 行がこのテーブルに属していません。

解説

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

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

使用例

[Visual Basic, C#, C++] GetParentRow を使用して、 DataTable 内の各 DataRow の各親行から値を出力する例を次に示します。

 
Private Sub GetParentRowForTable(thisTable As DataTable, relation As String)
    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.RelationName)
End Sub

[C#] 
private void GetParentRowForTable(DataTable thisTable, string 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.RelationName);
}

[C++] 
private:
 void GetParentRowForTable(DataTable* thisTable, String* 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->RelationName);
 }

[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 オーバーロードの一覧