Free mag vol1 | Page 939

CHAPTER 22  ADO.NET PART II: THE DISCONNECTED LAYER Figure 22-9. Displaying filtered data Again, the filtering logic is based on standard SQL syntax. For example, assume you want to obtain the results of the previous Select() invocation alphabetically, based on the pet name. In terms of SQL, this translates into a sort based on the PetName column. Fortunately, the Select() method has been overloaded to send in a sort criterion. // Sort by PetName. makes = inventoryTable.Select(filterStr, "PetName"); Call Select(), as seen here, if you want the results in descending order: // Return results in descending order. makes = inventoryTable.Select(filterStr, "PetName DESC"); In general, the sort string contains the column name, followed by ASC (ascending, which is the default) or DESC (descending). If necessary, you can separate multiple columns by commas. Finally, understand that a filter string can be composed of any number of relational operators. For example, assume you want to find all cars with an ID greater than 5. This helper function lets you accomplish that: private void ShowCarsWithIdGreaterThanFive() { // Now show the pet names of all cars with ID greater than 5. DataRow[] properIDs; string newFilterStr = "ID > 5"; properIDs = inventoryTable.Select(newFilterStr); string strIDs = null; for(int i = 0; i < properIDs.Length; i++) 885