Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering DataSet

Tags:

I have a DataSet full of costumers. I was wondering if there is any way to filter the dataset and only get the information I want. For example, to get CostumerName and CostumerAddress for a costumer that has CostumerID = 1

Is it possible?

like image 265
Erika Avatar asked May 15 '11 10:05

Erika


People also ask

What is filtering dataset?

What Does Data Filtering Mean? Data filtering in IT can refer to a wide range of strategies or solutions for refining data sets. This means the data sets are refined into simply what a user (or set of users) needs, without including other data that can be repetitive, irrelevant or even sensitive.

What is filtering in data visualization?

Filters reduce the amount of data shown in visualizations, canvases, and projects. The Range, List, Date, and Expression filter types are specific to either a visualization, canvas, or project. Filter types are automatically determined based on the data elements you choose as filters.

What is the use of filter data?

Filtering Data When data is filtered, only rows that meet the filter criteria will display and other rows will be hidden. With filtered data, you can then copy, format, print, etc., your data, without having to sort or move it first.


1 Answers

You can use DataTable.Select:

var strExpr = "CostumerID = 1 AND OrderCount > 2"; var strSort = "OrderCount DESC";  // Use the Select method to find all rows matching the filter. foundRows = ds.Table[0].Select(strExpr, strSort);   

Or you can use DataView:

ds.Tables[0].DefaultView.RowFilter = strExpr;   

UPDATE I'm not sure why you want to have a DataSet returned. But I'd go with the following solution:

var dv = ds.Tables[0].DefaultView; dv.RowFilter = strExpr; var newDS = new DataSet(); var newDT = dv.ToTable(); newDS.Tables.Add(newDT); 
like image 167
Kamyar Avatar answered Oct 12 '22 07:10

Kamyar