BindingSource.Filter:组合多个过滤器 C# Winforms

编程入门 行业动态 更新时间:2024-10-27 04:33:34
本文介绍了BindingSource.Filter:组合多个过滤器 C# Winforms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在编写一个连接到 Access 数据库的程序.我有 3 个搜索条件正在尝试组合.其中两个过滤器来自复选框,而第三个是搜索框.单独使用这 3 个效果很好.但是,当尝试连接过滤器时,它似乎只能识别CheckedSListFilter".我已经测试了连接字符串的多次迭代,但没有任何运气.我希望这只是一个语法问题.谢谢你的帮助.

I am writing a program that hooks into an Access Database. I have 3 search criteria I am attempting to combine. Two of the filters are derived from checkboxes, while the 3rd is a searchbox. Individually these 3 work great. However, when attempting to Concatenate the filters it seems to only recognize the 'CheckedSListFilter'. I have tested multiple iterations of the concatenated string without any luck. I'm hoping this is just a syntax issue. Thanks for your help.

        string SFilter = CheckedSListFilter();// method returns string "S = 'w1' OR S = 'w2' OR S = 'w3'"
        string PFilter = CheckedPStatusFilter();//method returns string "PA = 'True' OR "PB = 'True'"
        string CFilter = comboBox_SearchFields.Text;
        string filter = CFilter + " LIKE '" + "*" + textBox_search.Text + "*" + "'";//returns "R LIKE '*g*'"

                BindingSource bs = this.projectBindingSource;
                bs.Filter =  filter+" AND "+"("+PFilter +" OR "+SFilter+")";

推荐答案

我自己解决了这个问题.操作顺序让我绊倒了.最终做了这样的事情: bs.Filter = "("+SFilter+")"+" AND "+"("+PFilter+")"+" AND "+"("+PFilter+")";现在一切都按预期工作.

Solved this on my own. Order of operations was tripping me up. Ended up doing something like this: bs.Filter = "("+SFilter+")"+" AND "+"("+PFilter+")"+" AND "+"("+PFilter+")"; All now works as expected.

这篇关于BindingSource.Filter:组合多个过滤器 C# Winforms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 11:04:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1115338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   多个   过滤器   BindingSource   Filter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!