本文介绍了DataTable选择过滤器,而不是“之间”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想过滤一个价格范围的数据表。我想删除不在(例如)2和7之间的所有内容。在SQL中,我会做:NOT(2到7之间的价格)。但是在我的过滤器表达式中,我无法使用关键字between。什么是最好的解决方案?
I want to filter a datatable with a price range. I want to remove everything that is not between (for example) 2 and 7. In SQL I would do: NOT( price between 2 and 7). But in my filter expression I cannot use the keyword 'between'. What is the best solution?
推荐答案如果您引用 System.Data.DataSetExtensions LINQ for DataTables),您可以执行以下操作:
If you are referencing System.Data.DataSetExtensions (which enables LINQ for DataTables), you can do the following:
var query = myDataTable.Where(c => !(c.Price >= 2 && c.Price <= 7)); var myDataView = query.AsDataView(); // if you want to databind...更多推荐
DataTable选择过滤器,而不是“之间”
发布评论