如何使用关键字“IN”来使用 DataView 的 RowFilter过滤集合

发布于 2024-11-24 07:05:18 字数 239 浏览 1 评论 0原文

我想过滤数据视图中填充的集合。我为此使用的控件是多选复选框组合框。由此返回的字符串是“val1,val2,val3”。然后我将其传递给 sql 查询语句,以便能够用作我的 FilterExpression。但是,当将我的表达式分配给 dataView.RowFilter = SomethingFilterString 时,其中我的表达式为 Something IN (val1, val2, val3) ,会出现错误,指出找不到列 val1。有谁可以帮忙吗???

I would like to filter a collection populated in a DataView. The control I am using for this is a multi-select checkbox Combobox. The string returned from this is 'val1, val2, val3'. I then pass this to a sql query statement so as to be able to use as my FilterExpression. However,when assigning my expression to dataView.RowFilter = somethingFilterString which has my expression as Something IN (val1, val2, val3) is gives an error that it cannot find column val1. Anyone that can help please????

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

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

发布评论

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

评论(1

蓦然回首 2024-12-01 07:05:18

如果 val1、val2、val3 的值是字符串(例如,“apples、pears、bananas”),那么您需要查询文本来显示它们是字符串,否则必须假设它们是列名。

如果您正在构建像这样的逗号分隔列表:

var csv = string.Join(",", comboBox.SelectedValues); //guess on combo box property

...那么您可以执行类似的操作来获取带引号的值:

[Test]
public void SO6680770()
{
    var cols = new[] { "apples", "pears", "bananas" };

    var csv = string.Join(", ", cols.Select(s => string.Concat("'", s, "'")));

    Assert.AreEqual("'apples', 'pears', 'bananas'", csv);
}

If the values of val1, val2, val3 are strings (eg, "apples, pears, bananas"), then you need the query text to show they are strings otherwise it has to assume they are column names.

If you're building the comma-separated list like so:

var csv = string.Join(",", comboBox.SelectedValues); //guess on combo box property

... then you could do something like this to get the values with quotes instead:

[Test]
public void SO6680770()
{
    var cols = new[] { "apples", "pears", "bananas" };

    var csv = string.Join(", ", cols.Select(s => string.Concat("'", s, "'")));

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