tailieunhanh - Finding Rows in a DataTable

[ Team LiB ] Recipe Finding Rows in a DataTable Problem You need to find a row or group of rows in a DataTable meeting certain criteria. Solution Choose from the three techniques shown in the sample code to locate data in the table meeting user-specified criteria. | Team LiB Recipe Finding Rows in a DataTable Problem You need to find a row or group of rows in a DataTable meeting certain criteria. Solution Choose from the three techniques shown in the sample code to locate data in the table meeting user-specified criteria. The sample code contains two event handlers Sets up the sample by creating a DataTable containing the Orders table from the Northwind sample database. The default view of the table is bound to the data grid on the form. Find Uses three different techniques the method the method and the property to find rows in the Orders table matching the user-specified Country. The C code is shown in Example 3-8. Example 3-8. File Namespaces variables and constants using System using using using Table name constants private const String ORDERS_TABLE Orders Field name constants private const String ORDERID_FIELD OrderlD private const String SHIPCOUNTRY_FIELD ShipCountry . . . private void FindDataTableRowsForm_Load object sender e Fill the Orders table. SqlDataAdapter da new SqlDataAdapter SELECT FROM Orders S ql_ConnectString DataTable dt new DataTable ORDERS_TABLE dt dt Bind the table to the grid. private void findButton_Click object sender e Get the table bound to the grid. DataTable dt DataView .Table Build the filter using contents of the text box. String filter SHIPCOUNTRY_FIELD . Locate the records using the Select method of the DataTable. DataRow drc filter returned record s . Iterate over the collection of rows filtered in the previous step and find them in the table using the Find method of the