DataTableExtensions.AsDataView Método
Definição
Sobrecargas
| AsDataView(DataTable) |
Cria e retorna um objeto DataView habilitado para LINQ.Creates and returns a LINQ-enabled DataView object. |
| AsDataView<T>(EnumerableRowCollection<T>) |
Cria e retorna um objeto habilitado para LINQ DataView que representa a consulta de LINQ to DataSet.Creates and returns a LINQ-enabled DataView object representing the LINQ to DataSet query. |
AsDataView(DataTable)
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
Parâmetros
- table
- DataTable
O DataTable de origem com base no qual o DataView habilitado para LINQ é criado.The source DataTable from which the LINQ-enabled DataView is created.
Retornos
Um objeto DataView habilitado para LINQ.A LINQ-enabled DataView object.
Exemplos
O exemplo a seguir cria um DataView da tabela SalesOrderDetail e o define como a fonte de dados de um BindingSource objeto, que atua como um proxy para um DataGridView controle: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()
Comentários
DataView habilita cenários de vinculação de dados para LINQ to DataSet e podem ser criados com base em um tipo ou não tipado DataTable , fornecendo uma exibição padrão dessa tabela.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. A filtragem e a classificação podem ser definidas em DataView depois que foi criado de DataTable.Filtering and sorting can be set on the DataView after it has been created from a DataTable. O DataView é então associado a um controle de interface do usuário, como um DataGrid ou um DataGridView , fornecendo um modelo de ligação de dados simples.The DataView is then bound to a UI control, such as a DataGrid or a DataGridView, providing a simple data binding model.
Para obter mais informações e exemplos, consulte criando um objeto DataView.For more information and examples, see Creating a DataView Object.
Aplica-se a
AsDataView<T>(EnumerableRowCollection<T>)
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
Parâmetros de tipo
- T
O tipo de objetos na sequência de origem, normalmente DataRow.The type of objects in the source sequence, typically DataRow.
Parâmetros
- source
- EnumerableRowCollection<T>
A consulta de LINQ to DataSet de origem da qual o LINQ-habilitado DataView é criado.The source LINQ to DataSet query from which the LINQ-enabled DataView is created.
Retornos
Um objeto DataView habilitado para LINQ.A LINQ-enabled DataView object.
Exemplos
O exemplo a seguir cria um DataView dos pedidos online ordenados pelo total devido: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
Comentários
DataView habilita cenários de ligação de dados para LINQ to DataSet e podem ser criados a partir de uma consulta LINQ to DataSet.DataView enables data binding scenarios for LINQ to DataSet and can be created from a LINQ to DataSet query. O DataView representa a consulta em si e não é uma exibição na parte superior da consulta.The DataView represents the query itself, and is not a view on top of the query. O recém-criado DataView infere as informações de filtragem e classificação da consulta da qual ela foi criada.The newly created DataView infers the filtering and sorting information from the query it is created from. O DataView é então associado a um controle de interface do usuário, como um DataGrid ou um DataGridView , fornecendo um modelo de ligação de dados simples.The DataView is then bound to a UI control, such as a DataGrid or a DataGridView, providing a simple data-binding model.
O parâmetro T do parâmetro de entrada source só pode ser do tipo DataRow ou um tipo derivado de DataRow .The parameter T of the input parameter source can only be of type DataRow or a type derived from DataRow.
Os seguintes operadores de consulta, somente, têm suporte em uma consulta usada para criar DataView :The following query operators, only, are supported in a query used to create DataView:
Para obter mais informações e exemplos, consulte criando um objeto DataView.For more information and examples, see Creating a DataView Object.