DataView RowFilter中的撇号 [英] Apostrophe in DataView RowFilter
本文介绍了DataView RowFilter中的撇号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要基于动态字符串进行过滤的DataView:
I have a DataView that I'm trying to filter based on a dynamic string:
dv.RowFilter = "ContentTitle = '" + titleFilter + "'";
在某些情况下, titleFilter
包含一个撇号,该撇号会关闭过滤器查询并导致错误.
In some cases, titleFilter
contains an apostrophe, which is closing out the filter query and causing an error.
有没有办法让我逃脱那个角色?我无法替换.
Is there a way I can escape that character? I can't replace it.
推荐答案
只需将 titleFilter
字符串中的撇号(又称为引号)加
Simply double the apostrophe (a.k.a. quote) inside the titleFilter
string with
dv.RowFilter = "ContentTitle = '" + titleFilter.Replace("'", "''") + "'";
这篇关于DataView RowFilter中的撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文