Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the parent row of a DataRow.
GetParentRow(DataRelation) |
Gets the parent row of a DataRow using the specified DataRelation. |
GetParentRow(String) |
Gets the parent row of a DataRow using the specified RelationName of a DataRelation. |
GetParentRow(DataRelation, DataRowVersion) |
Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion. |
GetParentRow(String, DataRowVersion) |
Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion. |
Gets the parent row of a DataRow using the specified DataRelation.
public:
System::Data::DataRow ^ GetParentRow(System::Data::DataRelation ^ relation);
public System.Data.DataRow? GetParentRow(System.Data.DataRelation? relation);
public System.Data.DataRow GetParentRow(System.Data.DataRelation relation);
member this.GetParentRow : System.Data.DataRelation -> System.Data.DataRow
Public Function GetParentRow (relation As DataRelation) As DataRow
The DataRelation to use.
The parent DataRow of the current row.
A child row has multiple parents.
This row does not belong to the child table of the DataRelation object.
The row does not belong to a table.
The following example uses the GetParentRow to return the child DataRow objects for every child DataRelation in a DataTable. The value of each column in the row is then printed.
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 row in thisTable.Rows)
{
parentRow = row.GetParentRow(relation);
Console.Write("\table child row: " + row[1]);
Console.Write("\table 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);
}
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 row As DataRow
For Each row In thisTable.Rows
parentRow = row.GetParentRow(relation)
Console.Write(ControlChars.Tab & " child row: " _
& row(1).ToString())
Console.Write(ControlChars.Tab & " parent row: " _
& parentRow(1).ToString() & ControlChars.Cr)
Next row
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
In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.
The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
Gets the parent row of a DataRow using the specified RelationName of a DataRelation.
public:
System::Data::DataRow ^ GetParentRow(System::String ^ relationName);
public System.Data.DataRow? GetParentRow(string? relationName);
public System.Data.DataRow GetParentRow(string relationName);
member this.GetParentRow : string -> System.Data.DataRow
Public Function GetParentRow (relationName As String) As DataRow
The RelationName of a DataRelation.
The parent DataRow of the current row.
The relation and row do not belong to the same table.
A child row has multiple parents.
The row does not belong to the table.
The following example uses the GetParentRow to print a value from each parent row of each DataRow in a DataTable.
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 row in thisTable.Rows)
{
parentRow = row.GetParentRow(relation);
Console.Write("\table child row: " + row[1]);
Console.Write("\table 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);
}
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 row As DataRow
For Each row In thisTable.Rows
parentRow = row.GetParentRow(relation)
Console.Write(ControlChars.Tab + " child row: " _
+ row(1).ToString())
Console.Write(ControlChars.Tab + " parent row: " _
+ parentRow(1).ToString() + ControlChars.Cr)
Next row
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
In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.
The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion.
public:
System::Data::DataRow ^ GetParentRow(System::Data::DataRelation ^ relation, System::Data::DataRowVersion version);
public System.Data.DataRow? GetParentRow(System.Data.DataRelation? relation, System.Data.DataRowVersion version);
public System.Data.DataRow GetParentRow(System.Data.DataRelation relation, System.Data.DataRowVersion version);
member this.GetParentRow : System.Data.DataRelation * System.Data.DataRowVersion -> System.Data.DataRow
Public Function GetParentRow (relation As DataRelation, version As DataRowVersion) As DataRow
The DataRelation to use.
One of the DataRowVersion values specifying the version of the data to get.
The parent DataRow of the current row.
The row is null
.
-or-
The relation
does not belong to this table's parent relations.
A child row has multiple parents.
The relation's child table is not the table the row belongs to.
The row does not belong to a table.
The row does not have this version of data.
The following example uses the GetParentRow to return the child DataRow objects for every child DataRelation in a DataTable. The value of each column in the row is then printed.
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 row in thisTable.Rows)
{
parentRow = row.GetParentRow(relation, version);
Console.Write("\table child row: " + row[1]);
Console.Write("\table 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);
}
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 row As DataRow
For Each row In thisTable.Rows
parentRow = row.GetParentRow(relation, version)
Console.Write(ControlChars.Tab & " child row: " & _
row(1).ToString())
Console.Write(ControlChars.Tab & " parent row: " _
& parentRow(1).ToString() & ControlChars.Cr)
Next row
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
In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.
The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.
Use the HasVersion property to determine whether the DataRowVersion that you want exists.
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.
public:
System::Data::DataRow ^ GetParentRow(System::String ^ relationName, System::Data::DataRowVersion version);
public System.Data.DataRow? GetParentRow(string? relationName, System.Data.DataRowVersion version);
public System.Data.DataRow GetParentRow(string relationName, System.Data.DataRowVersion version);
member this.GetParentRow : string * System.Data.DataRowVersion -> System.Data.DataRow
Public Function GetParentRow (relationName As String, version As DataRowVersion) As DataRow
The RelationName of a DataRelation.
One of the DataRowVersion values.
The parent DataRow of the current row.
The relation and row do not belong to the same table.
A child row has multiple parents.
The row does not belong to the table.
The row does not have the requested DataRowVersion.
The following example uses the GetParentRow to print a value from each parent row of each DataRow in a DataTable.
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 row in thisTable.Rows)
{
parentRow = row.GetParentRow(relation, version);
Console.Write("\t child row: " + row[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);
}
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 row As DataRow
For Each row In thisTable.Rows
parentRow = row.GetParentRow(relation, version)
Console.Write(ControlChars.Tab & " child row: " _
& row(1).ToString())
Console.Write(ControlChars.Tab & " parent row: " _
& parentRow(1).ToString() & ControlChars.Cr)
Next row
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
In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.
The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.
Use the HasVersion property to determine whether the DataRowVersion that you want exists.
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Please sign in to use this experience.
Sign in