DataRow.GetParentRow 方法

定義

取得 DataRow 的父資料列。Gets the parent row of a DataRow.

多載

GetParentRow(DataRelation)

使用指定的 DataRow,取得 DataRelation 的父資料列。Gets the parent row of a DataRow using the specified DataRelation.

GetParentRow(String)

使用 DataRow 的指定 RelationName,取得 DataRelation 的父資料列。Gets the parent row of a DataRow using the specified RelationName of a DataRelation.

GetParentRow(DataRelation, DataRowVersion)

使用指定的 DataRowDataRelation,取得 DataRowVersion 的父資料列。Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion.

GetParentRow(String, DataRowVersion)

使用 DataRow 的指定 RelationNameDataRelation,取得 DataRowVersion 的父資料列。Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

GetParentRow(DataRelation)

使用指定的 DataRow,取得 DataRelation 的父資料列。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);
member this.GetParentRow : System.Data.DataRelation -> System.Data.DataRow
Public Function GetParentRow (relation As DataRelation) As DataRow

參數

relation
DataRelation

要使用的 DataRelationThe DataRelation to use.

傳回

目前資料列的父 DataRowThe parent DataRow of the current row.

例外狀況

relation 不屬於 DataTableThe relation does not belong to the DataTable.

-或--or-

資料列為 nullThe row is null.

子資料行有多個父代。A child row has multiple parents.

這個資料列不屬於 DataRelation 物件的子資料表。This row does not belong to the child table of the DataRelation object.

資料列不屬於資料表。The row does not belong to a table.

範例

下列範例會使用 GetParentRow,針對 DataTable中的每個子 DataRelation 傳回子 DataRow 物件。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

備註

DataSet中,GetParentRows 方法會傳回資料集所有父系 DataRelation 物件的集合。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable 也包含 ParentRelations 屬性所傳回 DataRelation 物件的集合。The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

另請參閱

GetParentRow(String)

使用 DataRow 的指定 RelationName,取得 DataRelation 的父資料列。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);
member this.GetParentRow : string -> System.Data.DataRow
Public Function GetParentRow (relationName As String) As DataRow

參數

傳回

目前資料列的父 DataRowThe 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.

範例

下列範例會使用 GetParentRow,在 DataTable中列印每個 DataRow 的每個父資料列的值。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

備註

DataSet中,GetParentRows 方法會傳回資料集所有父系 DataRelation 物件的集合。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable 也包含 ParentRelations 屬性所傳回 DataRelation 物件的集合。The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

GetParentRow(DataRelation, DataRowVersion)

使用指定的 DataRowDataRelation,取得 DataRowVersion 的父資料列。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);
member this.GetParentRow : System.Data.DataRelation * System.Data.DataRowVersion -> System.Data.DataRow
Public Function GetParentRow (relation As DataRelation, version As DataRowVersion) As DataRow

參數

relation
DataRelation

要使用的 DataRelationThe DataRelation to use.

version
DataRowVersion

其中一個 DataRowVersion 值,指定要取得的資料版本。One of the DataRowVersion values specifying the version of the data to get.

傳回

目前資料列的父 DataRowThe parent DataRow of the current row.

例外狀況

資料列為 nullThe row is null.

-或--or-

relation 不屬於這個資料表的父關聯。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.

範例

下列範例會使用 GetParentRow,針對 DataTable中的每個子 DataRelation 傳回子 DataRow 物件。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

備註

DataSet中,GetParentRows 方法會傳回資料集所有父系 DataRelation 物件的集合。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable 也包含 ParentRelations 屬性所傳回 DataRelation 物件的集合。The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

使用 HasVersion 屬性來判斷您想要的 DataRowVersion 是否存在。Use the HasVersion property to determine whether the DataRowVersion that you want exists.

另請參閱

GetParentRow(String, DataRowVersion)

使用 DataRow 的指定 RelationNameDataRelation,取得 DataRowVersion 的父資料列。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);
member this.GetParentRow : string * System.Data.DataRowVersion -> System.Data.DataRow
Public Function GetParentRow (relationName As String, version As DataRowVersion) As DataRow

參數

version
DataRowVersion

其中一個 DataRowVersion 值。One of the DataRowVersion values.

傳回

目前資料列的父 DataRowThe parent DataRow of the current row.

例外狀況

關聯和資料列不屬於相同資料表。The relation and row do not belong to the same table.

relationnullThe relation is null.

子資料行有多個父代。A child row has multiple parents.

資料列不屬於資料表。The row does not belong to the table.

資料列沒有要求的 DataRowVersionThe row does not have the requested DataRowVersion.

範例

下列範例會使用 GetParentRow,在 DataTable中列印每個 DataRow 的每個父資料列的值。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

備註

DataSet中,GetParentRows 方法會傳回資料集所有父系 DataRelation 物件的集合。In a DataSet, the collection of all parent DataRelation objects for the data set is returned by the GetParentRows method.

DataTable 也包含 ParentRelations 屬性所傳回 DataRelation 物件的集合。The DataTable also contains a collection of DataRelation objects, returned by the ParentRelations property.

使用 HasVersion 屬性來判斷您想要的 DataRowVersion 是否存在。Use the HasVersion property to determine whether the DataRowVersion that you want exists.

適用於