Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用c中的RowFilter筛选对象中包含每个项的数据表#_C#_Asp.net Mvc_Filter_Datatable - Fatal编程技术网

C# 如何使用c中的RowFilter筛选对象中包含每个项的数据表#

C# 如何使用c中的RowFilter筛选对象中包含每个项的数据表#,c#,asp.net-mvc,filter,datatable,C#,Asp.net Mvc,Filter,Datatable,我有一个数据表,我可以像这样过滤它 DataView dv = new DataView(table); dv.RowFilter = string.Format("[SAILING-DATE]='{0}'", "03/12/16");//step ONE 这将成功返回结果 现在我有一个这样的物体 var myObject = returnPorts(one).Split('|'); dv.RowFilter = string.Format("[SAILING-PORT]='{0}'",

我有一个数据表,我可以像这样过滤它

DataView dv = new DataView(table);
dv.RowFilter = string.Format("[SAILING-DATE]='{0}'", "03/12/16");//step ONE
这将成功返回结果

现在我有一个这样的物体

var myObject = returnPorts(one).Split('|');
 dv.RowFilter = string.Format("[SAILING-PORT]='{0}'", "Should filter with all the items in the myObject at once");//step TWO
myObject
包括5个项。所以我想在上面对
DataTable
中的所有项目进行筛选
myObject
。我不知道该怎么做。需要这样做吗

var myObject = returnPorts(one).Split('|');
 dv.RowFilter = string.Format("[SAILING-PORT]='{0}'", "Should filter with all the items in the myObject at once");//step TWO

我需要你的帮助。另一件事是我想立刻做第一步和第二步。我也需要帮助。非常感谢。

行过滤器使用相当基本的语法,但允许您在中使用

var parts = returnPorts(one).Split('|');
dv.RowFilter = string.Format("[SAILING-PORT] IN ('{0}')", String.Join("','", parts));
若要将其与日期合并,请将其添加到
零件中,或将其添加到以下格式:

var parts = returnPorts(one).Split('|');
dv.RowFilter = string.Format("[SAILING-PORT] IN ('{0}', '{1}')", 
                             "03/12/16", 
                             String.Join("','", parts));

这将把数组中的所有值连接成单个字符串。这将允许您筛选数组中的所有值。

这是完整答案
@freedomn-m的回答对我帮助很大。非常感谢

对于第一部分(使用对象中任意数量的项进行筛选)。thanx到@freedomn-m

var parts = returnPorts(one).Split('|');
dv.RowFilter = string.Format("[SAILING-PORT] IN ('{0}')", String.Join("','", parts));
对于第二部分-包含任意数量的条件

dv.RowFilter = string.Format("[SAILING-PORT] IN  ('{0}') AND [CRUISE-ONLY]=('{1}') AND [SAILING-DATE]=('{2}')", String.Join("','", threee), "YES", "03/12/16");

thanx是所有帮助我的人。

是的,当然。第一步是对日期进行筛选,第二步是使用端口进行筛选。AppCire使用thisClose创建您的帮助,但请查看使用该代码将生成什么IN子句
in('a,b,c')
这是一个单一的筛选值,需要在逗号的两侧添加一个引号。您的第一部分是正确的,非常好。但在第二部分中,
[SAILING-PORT]
[SAILING-DATE]
都是表中的两个不同列。我想用
来说明这两个列。例如
dv.RowFilter=“[CRUISE-ONLY]='YES'和[NOW-AVAIL]='YES'和[1A]'N/A'