我试图过滤一个有多列的DataView
,其中一些是数值。键入字符串时一切都很完美,但一旦输入数值(如检查信使#),它就会过滤掉。
我的守则如下:
private void tbxSearchCourier_KeyUp(object sender, KeyEventArgs e)
{
string outputInfo = "";
string[] keyWords = tbxSearchCourier.Text.Split(' ');
foreach (string word in keyWords)
{
if (outputInfo.Length == 0)
{
outputInfo = "('Courier #' LIKE '%" + word + "%' OR Name LIKE '%" + word + "%' OR Branch LIKE '%" + word + "%' OR 'Contact Number' LIKE '%" + word
+ "%' OR 'Email Address' LIKE '%" + word + "%')";
}
else
{
outputInfo += " AND ('Courier #' LIKE '%" + word + "%' OR Name LIKE '%" + word + "%' OR Branch LIKE '%" + word + "%' OR 'Contact Number' LIKE '%" + word
+ "%' OR 'Email Address' LIKE '%" + word + "%')";
}
}
CourierDV.RowFilter = outputInfo;
}
我在网上搜索解决方案但找不到任何有用的解决方案。为什么会发生这种情况,我该如何解决?
请考虑以下注释:
''
之间,使其成为字符串文字。[]
。integer
列和LIKE
运算符,首先应将其转换为string
,因为LIKE
是string
运算符。Courier #
,而不是标题/标题文本。例
dataView.RowFilter = "Convert([Some Column], System.String) LIKE '12%'";
更多信息
要了解有关过滤器支持语法的更多信息,请查看DataColumn.Expression
。