DataRelation の指定した RelationName と DataRowVersion を使用して、 DataRow の親行を取得します。
Overloads Public Function GetParentRow( _
ByVal relationName As String, _ ByVal version As DataRowVersion _) As DataRow
[C#]
public DataRow GetParentRow(stringrelationName,DataRowVersionversion);
[C++]
public: DataRow* GetParentRow(String* relationName,DataRowVersionversion);
[JScript]
public function GetParentRow(
relationName : String,version : DataRowVersion) : DataRow;
パラメータ
- relationName
DataRelation の RelationName 。 - version
DataRowVersion 値の 1 つ。
戻り値
現在の行の親 DataRow 。
例外
例外の種類 | 条件 |
---|---|
ArgumentException | リレーションシップと行が同じテーブルに属していません。 |
ArgumentNullException | relation が null 参照 (Visual Basic では Nothing) です。 |
RowNotInTableException | 行がこのテーブルに属していません。 |
VersionNotFoundException | 要求された DataRowVersion が行にありません。 |
解説
DataSet で、データ セットのすべての親 DataRelation オブジェクトのコレクションは、 GetParentRows メソッドによって返されます。
DataTable は、 ParentRelations プロパティが返す DataRelation オブジェクトのコレクションも格納します。
目的の DataRowVersion が存在するかどうかを確認するには、 HasVersion プロパティを使用します。
使用例
[Visual Basic, C#, C++] GetParentRow を使用して、 DataTable 内の各 DataRow の各親行から値を出力する例を次に示します。
Private Sub GetParentRowForTable _
(thisTable As DataTable, relation As String, 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.RelationName, _
DataRowVersion.Original)
End Sub
[C#]
private void GetParentRowForTable(DataTable thisTable, string 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.RelationName,
DataRowVersion.Original);
}
[C++]
private:
void GetParentRowForTable(DataTable* thisTable, String* 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->RelationName,
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 オーバーロードの一覧