为什么 COALESCE 不能与 RowFilter 一起使用?

发布于 2024-08-04 03:45:43 字数 1553 浏览 7 评论 0原文

我正在 WPF 中开发一个小型应用程序。我有一个名为 NameListBoxListBox,其 ItemsSource 属性设置为 DataView,从而显示客户列表名称。该名称由 3 部分组成:FirstNameMiddleNameLastName。我使用转换器在列表中显示客户的全名。一切工作正常(我认为这种细节水平足以了解整体情况)。

现在,我想在 NameListBox 上启用过滤,以便列表仅显示那些包含在名为 TextBox 中输入的文本的客户名称。代码>CustomerNameSearchBox。

通过在互联网上搜索,我发现了 DataViewRowFilter 属性 - 并且也对此进行了一些尝试。现在,当我尝试

private void CustomerNameSearchBox_TextChanged(object sender, TextChangedEventArgs e)
{
  //((DataView)NameListBox.ItemsSource).RowFilter = @"COALESCE(FirstName+' '+MiddleName+' '+LastName, COALESCE(FirstName+' '+LastName, COALESCE(FirstName, LastName))) LIKE '%" + CustomerNameSearchBox.Text + @"%'";
    ((DataView)NameListBox.ItemsSource).RowFilter = @"ISNULL(FirstName+' '+MiddleName+' '+LastName, ISNULL(FirstName+' '+LastName, ISNULL(FirstName, LastName))) LIKE '%" + CustomerNameSearchBox.Text + @"%'";
}

这个东西给了我预期的结果。但是等等..这里有一些奇怪的东西!

正如您所看到的,这两行的结构是相同的 - 只是用 COALESCE 代替了 ISNULL。但是当我取消注释第一行(并注释掉第二行)时,它不起作用!!!! 它在运行时在该行抛出异常,表示“表达式包含未定义的函数调用 COALESCE()。”!!!!

尽管 ISNULL 服务我此刻的目的是,我真的很好奇为什么会发生这种异常。而且,即使是像这样简单的事情似乎也

(...).RowFilter = @"COALESCE(FirstName,'')";

不起作用!!!! (这意味着它不仅仅是一个语法问题)

任何人都可以向我解释这种行为吗? 提前致谢。

标签: WPF SQL COALESCE ISNULL RowFilter

I'm developing a small application in WPF. I have a ListBox named NameListBox whose ItemsSource property is set to a DataView, and thus displays a list of customer names. The name is composed of 3 parts: FirstName, MiddleName, and LastName. I have used a converter to display the full name of customer in the list. Everything works fine (and I think this level of detail is enough to get the overall picture).

Now I want to enable filtering on the NameListBox such that the list should only displat those customer names that contain the text entered in the TextBox named CustomerNameSearchBox.

By searching on the Internet I came across RowFilter property of DataView - and also played with that a little. Now when I tried

private void CustomerNameSearchBox_TextChanged(object sender, TextChangedEventArgs e)
{
  //((DataView)NameListBox.ItemsSource).RowFilter = @"COALESCE(FirstName+' '+MiddleName+' '+LastName, COALESCE(FirstName+' '+LastName, COALESCE(FirstName, LastName))) LIKE '%" + CustomerNameSearchBox.Text + @"%'";
    ((DataView)NameListBox.ItemsSource).RowFilter = @"ISNULL(FirstName+' '+MiddleName+' '+LastName, ISNULL(FirstName+' '+LastName, ISNULL(FirstName, LastName))) LIKE '%" + CustomerNameSearchBox.Text + @"%'";
}

This thing gave me expected results. But wait.. there's something strange here!!!

As you can see, the structure of both lines is the same - only COALESCE in place of ISNULL. But when I uncomment the first line (and comment out the second) it does't work!!!! It throws an exception at runtime at that line saying "The expression contains undefined function call COALESCE()."!!!!

Though ISNULL serves my purpose at this moment, I'm really curious to know why this exception happens. Moreover, even a simple thing like

(...).RowFilter = @"COALESCE(FirstName,'')";

doesn't seem to work!!!! (It means its more than just a syntactical problem)

Can anyone explain me about this behavior??
Thanks in advance.

Tags : WPF SQL COALESCE ISNULL RowFilter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以心动 2024-08-11 03:45:43

Rowfilter 本身不是 SQL,其功能范围有限

MSDN:表达式语法

The Rowfilter isn't SQL as such and has a limited scope of functionality

MSDN: Expression syntax

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文