Creating and Using a DataView Object

Creating and Using a DataView Object In this section, you'll learn how to filter and sort rows with a DataView object. You create a DataView object using one of the following constructors | Creating and Using a DataView Object In this section you ll learn how to filter and sort rows with a DataView object. You create a DataView object using one of the following constructors DataView DataView DataTable myDataTable DataView DataTable myDataTable string filterExpression string sortExpression DataViewRowState rowState where myDataTable specifies the DataTable that your DataView is associated with. Your DataView will read the rows from this DataTable. The Table property of your DataView is set to myDataTable. filterExpression specifies a string containing the expression you want to filter the rows by. The RowFilter property of your DataView is set to filterExpression. sortExpression specifies a string containing the expression you want to sort the rows by. The Sort property of your DataView is set to sortExpression. rowState specifies an additional filter to apply to the rows rowState filters by the DataRowView-State of the DataViewRow objects in your DataView. The RowStateFilter of your DataView is set to rowState. Before you create a DataView you first need a DataTable from which to read rows. The following example creates and populates a DataTable named customersDT that contains rows from the Customers table SqlCommand mySqlCommand SELECT CustomerlD CompanyName Country FROM Customers SqlDataAdapter mySqlDataAdapter new SqlDataAdapter mySqlCommand DataSet myDataSet new DataSet myDataSet Customers DataTable customersDT Customers Let s say you want to filter the rows in CustomersDT to view just the customers in the UK. Your filter string expression would be string filterExpression Country UK Note Notice that UK is placed within single quotes. This is because UK is a string literal. Also let s say you want to sort those rows by ascending CustomerID column values and descending CompanyName .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU LIÊN QUAN
5    176    1
5    255    1
5    106    0
5    121    1
6    103    1
6    107    1
6    121    1
6    103    0
6    140    0
6    98    0
TÀI LIỆU MỚI ĐĂNG
22    84    1    12-06-2024
181    4    1    12-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.