DataTableExtensions.AsDataView Method

Definition

Overloads

AsDataView(DataTable)

Creates and returns a LINQ-enabled DataView object.

AsDataView<T>(EnumerableRowCollection<T>)

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

AsDataView(DataTable)

Source:
DataTableExtensions.cs
Source:
DataTableExtensions.cs
Source:
DataTableExtensions.cs

Creates and returns a LINQ-enabled DataView object.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Data::DataView ^ AsDataView(System::Data::DataTable ^ table);
public static System.Data.DataView AsDataView (this System.Data.DataTable table);
static member AsDataView : System.Data.DataTable -> System.Data.DataView
<Extension()>
Public Function AsDataView (table As DataTable) As DataView

Parameters

table
DataTable

The source DataTable from which the LINQ-enabled DataView is created.

Returns

A LINQ-enabled DataView object.

Examples

The following example creates a DataView from the SalesOrderDetail table and sets it as the data source of a BindingSource object, which acts as a proxy for a DataGridView control:

DataTable orders = dataSet.Tables["SalesOrderDetail"];

DataView view = orders.AsDataView();
bindingSource1.DataSource = view;

dataGridView1.AutoResizeColumns();
Dim orders As DataTable = dataSet.Tables("SalesOrderDetail")

Dim view As DataView = orders.AsDataView()
bindingSource1.DataSource = view
dataGridView1.AutoResizeColumns()

Remarks

DataView enables data-binding scenarios for LINQ to DataSet and can be created from a typed or untyped DataTable, providing a default view of that table. Filtering and sorting can be set on the DataView after it has been created from a DataTable. The DataView is then bound to a UI control, such as a DataGrid or a DataGridView, providing a simple data binding model.

For more information and examples, see Creating a DataView Object.

Applies to

AsDataView<T>(EnumerableRowCollection<T>)

Source:
DataTableExtensions.cs
Source:
DataTableExtensions.cs
Source:
DataTableExtensions.cs

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

public:
generic <typename T>
 where T : System::Data::DataRow[System::Runtime::CompilerServices::Extension]
 static System::Data::DataView ^ AsDataView(System::Data::EnumerableRowCollection<T> ^ source);
public static System.Data.DataView AsDataView<T> (this System.Data.EnumerableRowCollection<T> source) where T : System.Data.DataRow;
static member AsDataView : System.Data.EnumerableRowCollection<'T (requires 'T :> System.Data.DataRow)> -> System.Data.DataView (requires 'T :> System.Data.DataRow)
<Extension()>
Public Function AsDataView(Of T As DataRow) (source As EnumerableRowCollection(Of T)) As DataView

Type Parameters

T

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

Parameters

source
EnumerableRowCollection<T>

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

Returns

A LINQ-enabled DataView object.

Examples

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

DataTable orders = dataSet.Tables["SalesOrderHeader"];

EnumerableRowCollection<DataRow> query =
    from order in orders.AsEnumerable()
    where order.Field<bool>("OnlineOrderFlag") == true
    orderby order.Field<decimal>("TotalDue")
    select order;

DataView view = query.AsDataView();

bindingSource1.DataSource = view;
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

Remarks

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.

Applies to