若要形成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不支持不等于(<>、!=、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>