Export (0) Print
Expand All

DataTableExtensions.AsDataView Method (DataTable)

Creates and returns a LINQ-enabled DataView object.

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

public static DataView AsDataView(
	this DataTable table
)

Parameters

table
Type: System.Data.DataTable
The source DataTable from which the LINQ-enabled DataView is created.

Return Value

Type: System.Data.DataView
A LINQ-enabled DataView object.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type DataTable. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

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 (LINQ to DataSet).

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();


.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft