数据绑定和 LINQ to DataSetData Binding and LINQ to DataSet

数据绑定是在应用程序 UI 和业务逻辑之间建立连接的过程。Data binding is the process that establishes a connection between the application UI and business logic. 如果绑定具有正确的设置,并且数据提供适当的通知,则在数据更改其值时,绑定到该数据的元素会自动反映更改。If the binding has the correct settings and the data provides the proper notifications, when the data changes its value, the elements that are bound to the data reflect changes automatically. DataSet 是数据驻留在内存中的表示形式,不管包含的数据来自什么数据源,它都可以提供一致的关系编程模型。The DataSet is an in- memory representation of data that provides a consistent relational programming model, regardless of the source of the data it contains. 使用 ADO.NET 2.0 DataView 可以对存储在 DataTable 中的数据进行排序和筛选。The ADO.NET 2.0 DataView enables you to sort and filter the data stored in a DataTable. 数据绑定应用程序中经常会使用此功能。This functionality is often used in data-binding applications. 通过使用 DataView,您可以使用不同的排序顺序公开表中的数据,并且可以按行状态或基于筛选器表达式来筛选数据。By using a DataView, you can expose the data in a table with different sort orders, and you can filter the data by row state or based on a filter expression. 有关DataView对象的详细信息,请参阅dataviewFor more information about the DataView object, see DataViews.

LINQ to DataSet 允许开发人员通过使用DataSet 语言集成查询 (LINQ)Language-Integrated Query (LINQ)创建复杂、功能强大的查询。LINQ to DataSet allows developers to create complex, powerful queries over a DataSet by using 语言集成查询 (LINQ)Language-Integrated Query (LINQ). 但是,LINQ to DataSet 查询返回DataRow对象的枚举,这在绑定方案中是不容易使用的。However, a LINQ to DataSet query returns an enumeration of DataRow objects, which is not easily used in a binding scenario. 为了更轻松地进行绑定,可以DataView从 LINQ to DataSet 查询创建。To make binding easier, you can create a DataView from a LINQ to DataSet query. DataView将使用查询中指定的筛选和排序,但更适合用于数据绑定。This DataView uses the filtering and sorting specified in the query, but is better suited for data binding. LINQ to DataSet 通过提供LINQLINQ基于表达式的DataView筛选和排序来扩展的功能,这允许执行比基于字符串的筛选和排序更复杂、功能更强大的筛选和排序操作。LINQ to DataSet extends the functionality of the DataView by providing LINQLINQ expression-based filtering and sorting, which allows for much more complex and powerful filtering and sorting operations than string-based filtering and sorting.

请注意,DataView 表示查询本身,而不是处于查询前面的视图。Note that the DataView represents the query itself and is not a view on top of the query. DataView 绑定到 UI 控件(如 DataGridDataGridView),提供简单的数据绑定模型。The DataView is bound to a UI control, such as a DataGrid or a DataGridView, providing a simple data binding model. 也可以从 DataView 创建 DataTable,从而提供该表的默认视图。A DataView can also be created from a DataTable, providing a default view of that table.

本节内容In This Section

创建 DataView 对象Creating a DataView Object
提供有关创建 DataView 的信息。Provides information about creating a DataView.

使用 DataView 进行筛选Filtering with DataView
说明如何使用 DataView 进行筛选。Describes how to filter with the DataView.

使用 DataView 进行排序Sorting with DataView
说明如何使用 DataView 进行排序。Describes how to sort with the DataView.

在 DataView 中查询 DataRowView 集合Querying the DataRowView Collection in a DataView
提供有关查询由 DataRowView 公开的 DataView 集合的信息。Provides information about querying the DataRowView collection exposed by DataView.

DataView 性能DataView Performance
提供有关 DataView 和性能的信息。Provides information about DataView and performance.

如何:将 DataView 对象绑定到 Windows 窗体 DataGridView 控件How to: Bind a DataView Object to a Windows Forms DataGridView Control
说明如何将 DataView 对象绑定到 DataGridViewDescribes how to bind a DataView object to a DataGridView.

请参阅See also