資料繫結和 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 是記憶體中的資料表示,可提供一致的關聯式程式撰寫模型 (Programming Model),不論它所包含的資料來源為何都一樣。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,以不同排序順序公開 (Expose) 資料表中的資料,而且可以按照資料列狀態或根據篩選條件運算式來篩選資料。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 Language-Integrated Query (LINQ)Language-Integrated Query (LINQ)來建立複雜且功能強大的查詢。LINQ to DataSet allows developers to create complex, powerful queries over a DataSet by using Language-Integrated Query (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 藉DataView由提供LINQLINQ以運算式為基礎的篩選和排序,來擴充的功能,讓篩選和排序作業比以字串為基礎的篩選和排序更複雜且功能強大。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 Forms 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