DataTableExtensions.AsDataView(Of T) Method (EnumerableRowCollection(Of T))


Creates and returns a LINQ-enabled DataView object representing the LINQ to DataSet query.

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

Public Shared Function AsDataView(Of T As DataRow) (
	source As EnumerableRowCollection(Of T)
) As DataView


Type: System.Data.EnumerableRowCollection(Of T)

The source LINQ to DataSet query from which the LINQ-enabled DataView is created.

Return Value

Type: System.Data.DataView

A LINQ-enabled DataView object.

Type Parameters


The type of objects in the source sequence, typically DataRow.

DataView enables data binding scenarios for LINQ to DataSet and can be created from a LINQ to DataSet query. The DataView represents the query itself, and is not a view on top of the query. The newly created DataView infers the filtering and sorting information from the query it is created from. The DataView is then bound to a UI control, such as a DataGrid or a DataGridView, providing a simple data-binding model.

The parameter T of the input parameter source can only be of type DataRow or a type derived from DataRow.

The following query operators, only, are supported in a query used to create DataView:

For more information and examples, see Creating a DataView Object (LINQ to DataSet).

The following example creates a DataView of online orders ordered by total due:

Dim orders As DataTable = dataSet.Tables("SalesOrderHeader")

Dim query = _
    From order In orders.AsEnumerable() _
    Where order.Field(Of Boolean)("OnlineOrderFlag") = True _
    Order By order.Field(Of Decimal)("TotalDue") _
    Select order

Dim view As DataView = query.AsDataView()
bindingSource1.DataSource = view

.NET Framework
Available since 3.5
Return to top