Export (0) Print
Expand All

DataRelationCollection.AddRange Method

Copies the elements of the specified DataRelation array to the end of the collection.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)

'Declaration
Public Overridable Sub AddRange ( _
	relations As DataRelation() _
)

Parameters

relations
Type: System.Data.DataRelation()

The array of DataRelation objects to add to the collection.

If BeginInit has been called, AddRange does not add any objects to the collection until EndInit is called. At the time that EndInit is called, the collection will be populated with the items specified in the most recent call to AddRange. If AddRange is called multiple times within a BeginInit / EndInit sequence, only those items specified in the most recent call to AddRange are added.

Public Shared Sub AddRelations(dataSet As DataSet)
	Dim customerOrders As DataRelation = _
        New DataRelation("CustomerOrders", _
	    dataSet.Tables("Customers").Columns("customerId"), _
	    dataSet.Tables("Orders").Columns("customerId"))
	Dim orderDetails As DataRelation = _
        New DataRelation("OrderDetail", _
	    dataSet.Tables("Orders").Columns("orderId"), _
	    dataSet.Tables("OrderDetails").Columns("orderId"))

	dataSet.Relations.AddRange(New DataRelation() _
        {customerOrders, orderDetails})

	' Display names of all relations. 
	Dim relation As DataRelation
	For Each relation In dataSet.Relations
	  Console.WriteLine(relation.RelationName.ToString())
	Next 
End Sub

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show:
© 2015 Microsoft