System.Data.DataRow.SetParentRow C# (CSharp) Method

SetParentRow() public method

Sets current row's parent row with specified relation.
public SetParentRow ( DataRow parentRow, DataRelation relation ) : void
parentRow DataRow
relation DataRelation
return void
        public void SetParentRow(DataRow parentRow, DataRelation relation)
        {
            if (relation == null)
            {
                SetParentRow(parentRow);
                return;
            }

            if (parentRow == null)
            {
                SetParentRowToDBNull(relation);
                return;
            }

            if (_table.DataSet != parentRow._table.DataSet)
            {
                throw ExceptionBuilder.ParentRowNotInTheDataSet();
            }

            if (relation.ChildKey.Table != _table)
            {
                throw ExceptionBuilder.SetParentRowTableMismatch(relation.ChildKey.Table.TableName, _table.TableName);
            }

            if (relation.ParentKey.Table != parentRow._table)
            {
                throw ExceptionBuilder.SetParentRowTableMismatch(relation.ParentKey.Table.TableName, parentRow._table.TableName);
            }

            object[] parentKeyValues = parentRow.GetKeyValues(relation.ParentKey);
            SetKeyValues(relation.ChildKey, parentKeyValues);
        }

Same methods

DataRow::SetParentRow ( DataRow parentRow ) : void

Usage Example

Example #1
0
 private static void SetNestedParentRow(DataRow childRow, DataRow parentRow)
 {
     DataRelation rel = GetNestedParentRelation(childRow);
     //we should not set this row's parentRow if the table doesn't match.
     if (rel != null)
     {
         if (parentRow == null || rel.ParentKey.Table != parentRow.Table)
             childRow.SetParentRow(null, rel);
         else
             childRow.SetParentRow(parentRow, rel);
     }
 }
All Usage Examples Of System.Data.DataRow::SetParentRow