gpt4 book ai didi

c# - 过滤数据集

转载 作者:IT王子 更新时间:2023-10-29 04:37:11 24 4
gpt4 key购买 nike

我有一个装满客户的数据集。我想知道是否有任何方法可以过滤数据集并只获取我想要的信息。例如,为 CostumerID = 1

的客户获取 CostumerNameCostumerAddress

这可能吗?

最佳答案

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

或者你可以使用DataView:

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

更新 我不确定您为什么要返回数据集。但我会采用以下解决方案:

var dv = ds.Tables[0].DefaultView;
dv.RowFilter = strExpr;
var newDS = new DataSet();
var newDT = dv.ToTable();
newDS.Tables.Add(newDT);

关于c# - 过滤数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6007872/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com