Free mag vol1 | Page 937

CHAPTER 22  ADO.NET PART II: THE DISCONNECTED LAYER You should now be able to run your application and specify a car ID to delete from the DataTable. As you remove DataRow objects from the DataTable, you will notice that the grid’s UI is updated immediately; this occurs because it is bound to the state of the DataTable object. Selecting Rows Based on Filter Criteria Many data-centric applications require the need to view a small subset of a DataTable’s data, as specified by some sort of filtering criteria. For example, assume you want to see only a certain make of automobile from the in-memory DataTable (e.g., only BMWs). You’ve already seen how the Select() method of the DataTable class allows you to find a row to delete; however, you can also use this method to grab a subset of records for display purposes. To see this in action, update your UI again, this time allowing users to specify a string that represents the make of the automobile they want to see (see Figure 22-8) using a new TextBox (named txtMakeToView) and a new Button (named btnDisplayMakes). Figure 22-8. Updating the UI to enable row filtering The Select() method has been overloaded a number of times to provide different selection semantics. At its most basic level, the parameter sent to Select() is a string that contains some conditional operation. To begin, observe the following logic for the Click event handler of your new button: 883