次の方法で共有


DataRow.GetParentRow メソッド (DataRelation, DataRowVersion)

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

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

パラメータ

  • relation
    使用する DataRelation
  • version
    取得するデータのバージョンを指定する DataRowVersion 値の 1 つ。

戻り値

現在の行の親 DataRow

例外

例外の種類 条件
ArgumentNullException 行が null 参照 (Visual Basic では Nothing) です。

relation は、このテーブルの親リレーションシップに属していません。

InvalidConstraintException このリレーションシップの子テーブルは、この行が属しているテーブルではありません。
RowNotInTableException この行はテーブルに属していません。
VersionNotFoundException このバージョンのデータが行にありません。

解説

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

DataTable は、 ParentRelations プロパティが返す DataRelation オブジェクトのコレクションも格納します。目的の DataRowVersion が存在するかどうかを確認するには、 HasVersion プロパティを使用します。

使用例

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

 
Private Sub GetParentRowForTable _
(thisTable As DataTable, relation As DataRelation, version As DataRowVersion)
    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, version)
        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)
    ' Print only original versions of parent rows.
    GetParentRowForTable(thisTable, relation, DataRowVersion.Original)
End Sub

[C#] 
private void GetParentRowForTable(DataTable thisTable, DataRelation relation,
DataRowVersion version) {
   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, version);
      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];
   // Print only original versions of parent rows.
   GetParentRowForTable(thisTable, relation,
      DataRowVersion.Original);
}

[C++] 
private:
 void GetParentRowForTable(DataTable* thisTable, DataRelation* relation,
 DataRowVersion version) {
    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, version);
       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];
    // Print only original versions of parent rows.
    GetParentRowForTable(thisTable, relation,
       DataRowVersion::Original);
 }

[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 | DataRowVersion | GetChildRows | GetParentRow | Relations