DataTableExtensions.AsDataView 方法

定义

重载

AsDataView(DataTable)

创建并返回支持 LINQ 的 DataView 对象。Creates and returns a LINQ-enabled DataView object.

AsDataView<T>(EnumerableRowCollection<T>)

创建并返回一个支持 LINQ 的 DataView 对象,该对象表示 LINQ to DataSetLINQ to DataSet 查询。Creates and returns a LINQ-enabled DataView object representing the LINQ to DataSetLINQ to DataSet query.

AsDataView(DataTable)

创建并返回支持 LINQ 的 DataView 对象。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

参数

table
DataTable

从中创建支持 LINQ 的 DataTable 的源 DataViewThe source DataTable from which the LINQ-enabled DataView is created.

返回

支持 LINQ 的 DataView 对象。A LINQ-enabled DataView object.

示例

下面的示例从 SalesOrderDetail 表创建一个 @no__t 0,并将其设置为 @no__t 的对象的数据源,该对象充当 @no__t 2 控件的代理: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()

注解

@no__t 启用 @no__t 的数据绑定方案,可以从类型化或非类型化的 DataTable 进行创建,并提供该表的默认视图。DataView enables data-binding scenarios for LINQ to DataSetLINQ to DataSet and can be created from a typed or untyped DataTable, providing a default view of that table. 在从 DataView 创建 DataTable 后,可以在其上设置筛选和排序。Filtering and sorting can be set on the DataView after it has been created from a DataTable. 然后,将 DataView 绑定到 UI 控件,如 DataGridDataGridView,提供简单的数据绑定模型。The DataView is then bound to a UI control, such as a DataGrid or a DataGridView, providing a simple data binding model.

有关详细信息和示例,请参阅创建 DataView 对象For more information and examples, see Creating a DataView Object.

AsDataView<T>(EnumerableRowCollection<T>)

创建并返回一个支持 LINQ 的 DataView 对象,该对象表示 LINQ to DataSetLINQ to DataSet 查询。Creates and returns a LINQ-enabled DataView object representing the LINQ to DataSetLINQ 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

类型参数

T

源序列中的对象类型(通常为 DataRow)。The type of objects in the source sequence, typically DataRow.

参数

source
EnumerableRowCollection<T>

从中创建支持 LINQ 的 DataView 的源 LINQ to DataSetLINQ to DataSet 查询。The source LINQ to DataSetLINQ to DataSet query from which the LINQ-enabled DataView is created.

返回

支持 LINQ 的 DataView 对象。A LINQ-enabled DataView object.

示例

下面的示例创建一个 DataView 的联机订单,按总计到期: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

注解

@no__t 启用 @no__t 的数据绑定方案,可通过 @no__t 查询进行创建。DataView enables data binding scenarios for LINQ to DataSetLINQ to DataSet and can be created from a LINQ to DataSetLINQ to DataSet query. @No__t-0 表示查询本身,而不是查询顶部的视图。The DataView represents the query itself, and is not a view on top of the query. 新创建的 DataView 可从创建它的查询推断筛选和排序信息。The newly created DataView infers the filtering and sorting information from the query it is created from. 然后,将 DataView 绑定到 UI 控件,如 DataGridDataGridView,提供简单的数据绑定模型。The DataView is then bound to a UI control, such as a DataGrid or a DataGridView, providing a simple data-binding model.

输入参数 T 的参数 source 的类型只能是 DataRow 或从 DataRow 派生的类型。The parameter T of the input parameter source can only be of type DataRow or a type derived from DataRow.

以下查询运算符仅在用于创建 DataView 的查询中受支持:The following query operators, only, are supported in a query used to create DataView:

有关详细信息和示例,请参阅创建 DataView 对象For more information and examples, see Creating a DataView Object.

适用于