过滤数据集

编程入门 行业动态 更新时间:2024-10-11 07:30:03
本文介绍了过滤数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个DataSet充分的costumers。我在想,如果有任何的方式来过滤数据集,只得到了我想要的信息。例如,要获得 CostumerName 和 CostumerAddress 为具有负荷消费 CostumerID = 1

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

这可能吗?

推荐答案

您可以使用 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);

或者你可以使用数据视图:

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

更新我不知道为什么你想有一个DataSet返回。不过,我会去用以下解决方案:

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);

更多推荐

过滤数据集

本文发布于:2023-10-31 09:15:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545699.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!