数据集表过滤:如何过滤列“包含"列的行.一个值. [英] Dataset table filtering: How to filter for rows where column "contains" a value.

查看:66
本文介绍了数据集表过滤:如何过滤列“包含"列的行.一个值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据集表,其中包含一个名为"Frequency"的列.以下是该列中包含的值的示例:

ID频率
------ ----------
1 30,90
2 30,90
3 90
4 30,90
5 90,365
6 90
7 15,180

我正在尝试提出一个过滤器表达式,该表达式将使我只能选择频率"列包含值"30"的那些行.我能想到的唯一方法就是使用"LIKE"或"CONTAINS"运算符.

以下是尝试使用"LIKE"的方法

I have a dataset table that contains a column named "Frequency". The following are examples of the values contained in that column:

ID Frequency
------ ----------
1 30,90
2 30,90
3 90
4 30,90
5 90,365
6 90
7 15,180

I''m trying to come up with a filter expression that will allow me to select only those rows where column Frequency contains the value "30". The only ways that I can think of to approach this would be to use "LIKE" or "CONTAINS" operators.

The following is an attempt to use "LIKE"

dSet.Tables(0).DefaultView.RowFilter = "''30'' IN (Frequency)"


这将产生错误:{在IN运算符的表达式列表中仅允许使用常量表达式."}

以下是我尝试使用"CONTAINS"的尝试:


This produces the error: {"Only constant expressions are allowed in the expression list for the IN operator."}

The following is my attemp at useing "CONTAINS":

dSet.Tables(0).DefaultView.RowFilter = "Frequency contains (30))"


这将产生错误:{语法错误:包含"运算符后缺少操作数."}

我已经尝试了CONTAINS语法的几种变体...我不确定过滤语法是否支持它.

朝着正确方向的任何微调将不胜感激.


This produces the error: {"Syntax error: Missing operand after ''contains'' operator."}

I''ve tried several variations on the CONTAINS syntax... I''m not so sure that it is supported in filtering syntax.

Any nudge in the right direction would be greatly appreciated.

推荐答案

您正在寻找

You''re looking for

dSet.Tables(0).DefaultView.RowFilter = "Frequency LIKE ''*30*''";



但是,这还将选择值是300、130等的行.因此,仅获取值30时,您将需要类似以下内容:



However, this will also select rows where the value is 300, 130, etc. So to get only values of 30 you''d need something like:

dSet.Tables(0).DefaultView.RowFilter = "Frequency = ''30'' OR Frequency LIKE ''30,*'' OR Frequency LIKE ''*,30''";



等等,以便您获得所有的可能性.

如果您使用的是框架的v3.5或更高版本,则可以使用LINQ制作可以用作数据源的数据视图.



and so on so that you get all of the possibilities.

If you''re using v3.5 or later of the framework you can use LINQ to make a dataview that you can use as a datasource.

var view = from DataRow row in dSet.Tables(0).Rows
           from frequency in row.Frequency.Split(new[]{'',''})
           where frequency == "30"
           select row;


使用此
dSet.Tables[0].DefaultView.RowFilter = "Frequency like ''%30%'')";



希望这对您有用.



hope this will work for you.


这篇关于数据集表过滤:如何过滤列“包含"列的行.一个值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆