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?
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.
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With