记录集过滤器的问题
我在旧版 ASP Classic 代码中的 ADO 记录集上使用筛选器时遇到问题,并且我试图了解我想要执行的操作是否不受支持,或者我是否只是做错了。
我有一个项目记录集,它们的状态为 1(活动)或 0(非活动),以及一个可选的 End_Date。在我的管理用户界面中,我有一个控件来显示所有项目或仅显示应向最终用户显示的项目: Status = 1 AND ( End_Date is null OR End_Date > Date() )
To实现该逻辑,我尝试过:
rs.Filter = "Status = 1 AND ( End_Date = null OR End_Date > #" & Date() & "# )"
但
ADODB.Recordset (0x800A0BB9)
Unknown runtime error
经过多次闲逛,ADO 似乎不喜欢 End_Date 条件周围的分组括号与 AND 条件相结合。如果我把括号去掉,这是可行的:
rs.Filter = "Status = 1 AND End_Date = null OR End_Date > #" & Date() & "#"
但这只是一个意外——看起来过滤条件是按顺序评估的,所以我得到了我想要的结果。如果我将 AND 更改为 OR,则括号起作用:
rs.Filter = "Status = 1 OR ( End_Date = null OR End_Date > #" & Date() & "# )"
但当然,这种逻辑是错误的 - 它显示活动但过期的项目。
奇怪的是,如果我改变条件,它会再次中断:
rs.Filter = "End_Date = null OR Status = 1 AND End_Date > #" & Date() & "# "
因相同的 ADODB 错误而崩溃。
我似乎无法预测什么会起作用,什么不会起作用,而且我读过的文档对于预期的语法(它不是纯粹的 T-SQL!)、限制等以及我的所有示例都非常粗略。我见过最多有两个条件。我不认为我的条件有那么复杂。谁能告诉我我想做的事情是否受到支持,是否有更好的方法来做到这一点,或者向我指出与这种逻辑相匹配的综合文档和示例?
谢谢!
I'm having trouble with a filter on an ADO Recordset in legacy ASP Classic code, and I'm trying to understand if what I'm trying to do is not supported, or if I'm just doing it wrong.
I have a recordset of Items, and they have a Status of 1 (active) or 0 (inactive), and an optional End_Date. In my administrative user interface, I have a control to show all items or only those that should be displayed to end-users: Status = 1 AND ( End_Date is null OR End_Date > Date() )
To implement that logic, I tried:
rs.Filter = "Status = 1 AND ( End_Date = null OR End_Date > #" & Date() & "# )"
but I get
ADODB.Recordset (0x800A0BB9)
Unknown runtime error
After much fooling around, it seems that ADO doesn't like the grouping parens around the End_Date conditions in combination with the AND condition. If I take the parens out, this works:
rs.Filter = "Status = 1 AND End_Date = null OR End_Date > #" & Date() & "#"
But that's just an accident -- it looks like the filter conditions are evaluated in order, and so I get the results I want. If I change the AND to OR, the parens work:
rs.Filter = "Status = 1 OR ( End_Date = null OR End_Date > #" & Date() & "# )"
But of course that logic is wrong -- it shows Active but expired items.
Strangely, if I move the conditions around, it breaks again:
rs.Filter = "End_Date = null OR Status = 1 AND End_Date > #" & Date() & "# "
crashes with the same ADODB error.
I can't seem to predict what will and won't work, and the docs I've read are very sketchy on the syntax expected (it's not pure T-SQL!), the limitations, etc. and all the examples I've seen have at most two conditions. I don't think my conditions are all that complex. Can anyone tell me if what I'm trying to do is supported, if there's a better way to do it, or point me to comprehensive docs and samples that match this kind of logic?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ADO 记录集对象过滤器属性:
所以你必须像这样构建你的过滤器:
ADO Recordset Object Filter Property:
So you would have to construct your filter like this:
我知道您正在使用遗留代码,并且可能其他事情正在工作,但是如何在这个特定页面中打开记录集?您是否使用 adovbs.inc 中定义的某些常量?
例如:
I know that you are working with legacy code and probably other things are working, but how do you open the recordset in this specific page? Are you using some constant defined in adovbs.inc?
For example:
当你尝试这个时会发生什么......
What happens when you try this...