Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

Finding and Sorting Data in DataSets

By Exforsys | on July 15, 2005 |
VB.NET 2005

Finding and Sorting Data in DataSets

In this tutorial you will learn about Finding and Sorting Data in DataSets – Filtering on Row State and Version, Sorting and Data View Manager.

Finding and Sorting Data in DataSets

Using the table’s Select method or the RowFilter property of a data view, the user can filter records in a data table to make available only the required records. This is useful when the user wants to work with different subsets of the records in a dataset table. To specify filter criteria, the user can use the same expression syntax used to create column expressions. The filter expression is evaluated as a Boolean expression; if the expression returns true, the record is included. A filter expression might look like the following:

Price > 10.00

Filtering on Row State and Version

A dataset can maintain different versions of records in tables. When records are first filled in, the dataset contains the original version of the record. If record is changed, the dataset maintains a different version — the current version — that reflects the changes. A property on the record indicates whether the record is unmodified, updated, new, or deleted

A common use for filters is to specify only the current versions of records in the data table. If records have been changed, there are two versions of a record–the current version reflecting the change and the original version representing the record before any changes were made. Records are also flagged according to their status: new, unchanged, deleted, or modified. A deleted record, for example, still exists in the data table, but its row-state flag has been set to deleted.

Sorting

Sorting is similar to filtering, in that you specify a sort expression. A typical sort expression is simply the name of the column to sort by. For example, to sort by the OrderDate column, the user msut specify the sort expression OrderDate. However, the user can sort by the value of any expression, including calculated values. If table’s Select method is called, the sort expression is passed as a parameter. If DataViews are being used, the sort expression is to be specified as the value of the view’s Sort property.

Data View Manager

Individual DataViews can be defined to sort or filter the data in each DataSet table. If the DataSet contains multiple tables, an alternative is to create a DataView manager (a DataViewManager object). The DataView manager works something like a dataset-wide data view. It provides a single object that manages a collection of DataViews, each of which is associated with a specific table in a dataset. To use a DataView manager, the user must create and configure it in code. There is no design-time object that can be added to a form or component. This means that controls are bound to the DataView manager in code, as there is no design-time component to bind them to.

The following project will illustrate the filtering and sorting of the data.

1. Create a new Windows application project.
2. Add three labels, one DataGridView, one ComboBox and a button to the Form
3. And arrange them as shown in the screenshot below
4. Now go to the codes page and add the following codes.

Click here to veiw sample code

1. Create a SqlConnection object whose constructor will take the connectString as the parameter.
2. Create SqlDataAdapter whose constructor will take the SqlStatement and the connection object as parameters.
3. Instantiating a DataSet and a DataView.
4. Call the fill method of the SqlDataAdapter and fill the DataSet.
5. Create a view.
6. To the ComboBox add the name of the table columns are to be sorted on.
7. Instantiate a DataView object that will be based on the DataSet table
8. Call the sort method of dataview from within the EventHandler of ComboBox selectedIndexChanged.
9. Press F5 to execute the code.
10. The program allows the user change the sort order just by choosing the fields in the combo box. The screenshots of the program is given below.

The DataGridView before Sorting:

The DataGridView after sorting on Name:

In the same way table data can be filtered. In this case all the instructions given for the above case holds good. The only change is in the EventHandler for the ComboBox. Instead of writing code for sorting, the activity for filtering will be defined. The Additional lines of code for this demo is given below:

Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged

Dim filtStr As String

filtStr = Me.ComboBox2.Text

Label3.Text = "The Data is Filtered for all Names starting with alphabet " & filtStr

dv.RowFilter = "Name like ‘" & filtStr & "*’"

End Sub

Now press F5 to execute the program. The screenshot given below shows the initial Screen.

The Screenshot Below shows the Screen With filtered data:

« « Using XML Data
Data Manipulation with ADO.NET » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 394 Followers
  • Popular
  • Recent
  • VB.NET Validation Controls

    July 4, 2005 - 0 Comment
  • The .NET Framework Architecture Part 2

    May 30, 2005 - 0 Comment
  • The File Types Editor

    August 9, 2005 - 0 Comment
  • Building Graphical Interface elements

    June 11, 2005 - 0 Comment
  • SQL Server Stored Procedures

    July 11, 2005 - 0 Comment
  • Web Application Testing in VB.NET 2005

    July 28, 2005 - 0 Comment
  • Differences between VB.NET 1.0 and VB.NET 2.0

    May 31, 2005 - 0 Comment
  • VB.NET Windows Application Testing

    August 9, 2005 - 0 Comment
  • Visual Studio Adding Controls to Windows Form

    June 20, 2005 - 0 Comment
  • Working with File System in .NET

    July 11, 2005 - 0 Comment
  • Microsoft .NET Creating Installation Components

    August 10, 2005 - 0 Comment
  • Shared Assembly

    August 9, 2005 - 0 Comment
  • The File Types Editor

    August 9, 2005 - 0 Comment
  • Tracing VB.NET Windows Application

    August 9, 2005 - 0 Comment
  • VB.NET Windows Application Testing

    August 9, 2005 - 0 Comment
  • The Registry Editor in Visual Studio.NET 2005

    August 4, 2005 - 0 Comment
  • Customizing Setup Project in Visual Studio.NET 2005

    August 4, 2005 - 0 Comment
  • Deploying Windows Applications In Visual Studio.NET 2005

    August 3, 2005 - 0 Comment
  • Debugging Windows Applications In Visual Studio.NET 2005

    August 3, 2005 - 0 Comment
  • Working with Legacy Code and COM Components

    July 30, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Microsoft .NET Creating Installation Components
  • Shared Assembly
  • The File Types Editor
  • Tracing VB.NET Windows Application
  • VB.NET Windows Application Testing

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT