tailieunhanh - 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 .
đang nạp các trang xem trước