How to filter data in dataset


 

Dataset is collection of data of Tables stored in Client Memory. In some scenario we want to filter the data without submitting another request to the database server.Dataset provide an option to filter the data based on condition. 

SqlDataAdapter da = new SqlDataAdapter(“select
empolyeename,Department,salary from employees inner join department on  employees.deptid= department.deptid”
, con);
 

DataSet ds = new
DataSet();

da.Fill (ds,“details”);

 

In the dataset if there is a requirement to filter the data for particular department .For example we assume dept as “Software”.
In this case we can use Data view


 
DataView dv = new DataView();

dv=ds.Tables[“details”].DefaultView;

dv.RowFilter=“Department =’Software‘”;

GridView1.DataSource = dv;

GridView1.DataBind();

Advertisements
This entry was posted in Articles and tagged . Bookmark the permalink.

One Response to How to filter data in dataset

  1. Pingback: 2010 in review « What i know is

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s