C# DataTable RowFilter 过滤

若要形成RowFilter值,请指定列的名称,后跟一个运算符和一个要筛选的值。该值必须用引号括起来。
//数据集中这列为null或者“”都过滤掉
pds.Tables[0].DefaultView.RowFilter = "字段名='' or 字段名 is  null";
//pds.Tables[0].DefaultView.RowFilter = "YHZHBH='00'";
//绑定
this.grid1.DataSource = pds.Tables[0].DefaultView;
DataTable dt = DataView.ToTable();正确的。
DataTable dt = DataView.Table; 获取的是原来构造DataView的那个原表(没有过滤之前的那个表)。

重点在于DataView是DateTable相关联 的一个视图而已,无论你如何使用RowFilter,DataView虽然被改变,但 DateTable数据不会减少,所以你不要幻想连续使用多个RowFilter 来得到叠加过滤的效果,一个DataView只支持一个RowFilter,你只能使用 not ,and 来连接多个过滤条件。

<wbr><p style="text-indent:2em">不过RowFilter不支持不等于(&lt;&gt;、!=、not like),不过如果只是单纯的对确定的字符串操作,可以用in和not in,数据库查询语句则不行。</p> <p style="text-indent:2em">eg:</p> <p style="text-indent:2em"></p> <pre code_snippet_id="147208" snippet_file_name="blog_20140108_2_9664158" name="code" class="csharp">dt.DefaultView.RowFilter = "Name in ('zhang')"; dt.DefaultView.RowFilter = "Name not in ('zhang')"; dt.DefaultView.RowFilter = "Name in (select Name from StudentInfo)"; //错误</pre> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:15px">若要形成RowFilter值,请指定列的名称,后跟一个运算符和一个要筛选的值。该值必须用引号括起来。</p> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:15px">例如:</p> <pre code_snippet_id="147208" snippet_file_name="blog_20140123_3_2449758" name="code" class="csharp">"LastName = 'Smith'"</pre> <p style="margin-top:0px; margin-bottom:0px; padding-bottom:15px">若要只返回那些具有空值的列,请使用以下表达式:</p> <pre code_snippet_id="147208" snippet_file_name="blog_20140123_4_8196615" name="code" class="csharp">"Isnull(Col1,'Null Column') = 'Null Column'"</pre> <br><br><p></p> <br><p style="font-family:'Microsoft YaHei UI','Microsoft YaHei',SimSun,'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif; color:rgb(42,42,42); margin-top:0px; margin-bottom:0px; padding-bottom:15px; line-height:18px; font-size:13px"> <br></p> <br><br><p></p> <p style="text-indent:2em"><br></p> </wbr>
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值