Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Accessing Data
 How to: Filter and Sort Data
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Data Access in Client and Middle-Tier Programming
How to: Filter and Sort Data

You filter data by setting the Filter property to a string expression that returns the desired records.

You sort data by setting the Sort property to the column name you want to sort on; append DESC to sort in descending order, or append ASC to sort in ascending order.

NoteNote:

If your application does not use BindingSource components, then you can filter and sort data using DataView objects. For more information, see DataViews (ADO.NET).

To filter data using a BindingSource component

  • Set the Filter property to the expression you want to return. For example, the following code returns customers with a CompanyName that starts with "B":

    Visual Basic
    CustomersBindingSource.Filter = "CompanyName like 'B'"
    
    C#
    customersBindingSource.Filter = "CompanyName like 'B'";
    

To sort data using a BindingSource component

  • Set the Sort property to the column you want to sort on. For example, the following code sorts customers on the CompanyName column in descending order:

    Visual Basic
    CustomersBindingSource.Sort = "CompanyName Desc"
    
    C#
    customersBindingSource.Sort = "CompanyName Desc";
    
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
ahamed_gad86@hotmail.com      Hero_gad   |   Edit   |   Show History

You forget important thing

CustomersBindingSource.Filter = "CompanyName like 'B%'"

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker