DekGenius.com
[ Team LiB ] Previous Section Next Section

27.3 Collections Reference

ChildColumns

DataColumn[] cols = DataRelation.ChildColumns;

This returns an array with all the child DataColumn objects for this relationship. Usually, this is a single column from the child DataTable. However, if they are all a part of the same relationship, you can relate multiple columns using one of the overloaded DataRelation constructors.

Example

The following code snippet retrieves the first child DataColumn and displays its name:

DataColumn col = dr.ChildColumns[0];
Console.WriteLine("The linked column child is: " + col.ColumnName);
ExtendedProperties

PropertyCollection props = DataRelation.ExtendedProperties;

Contains a PropertyCollection that can store any amount of miscellaneous information about the DataRelation. For example, you can store information about the parent and child columns or how the relationship should be validated according to custom validation functions you may have created. The information in the ExtendedProperties collection is for use by your code only; it isn't used by the .NET framework (although any strings you add to the PropertyCollection are retained in serialized DataSet XML.

The ProperyCollection is a name/value dictionary that derives from the Hashtable class. Most disconnected data objects provide an ExtendedProperties collection, including the DataSet, DataColumn, DataTable, and Constraint classes.

Example

The following code snippet stores the data type of the child DataColumn in the PropertyCollection:

// Determine the data type for the linked column.
Type dataType = dr.ChildColumns[0].DataType;

// Store it in the extended properties for future reference.
dr.ExtendedProperties["ColumnDataType"] = dataType.ToString();

Note

Items in the PropertyCollection must be strings if you want them to persist when the DataSet is written to XML.

ParentColumns

DataColumn[] cols = DataRelation.ParentColumns;

This returns an array with all the parent DataColumn objects for this relationship. Typically, this is a single column from the parent DataTable. However, if they are all a part of the same relationship, you can relate multiple columns using one of the overloaded DataRelation constructors.

Example

The following code snippet retrieves the first parent DataColumn and displays its name:

DataColumn col = dr.ParentColumns[0];
Console.WriteLine("The linked column parent is: " + col.ColumnName);
    [ Team LiB ] Previous Section Next Section