c# - DataView RowFilter 中的撇号

标签 c# asp.net

我有一个 DataView,我正尝试根据动态字符串进行过滤:

dv.RowFilter = "ContentTitle = '" + titleFilter + "'";

在某些情况下,titleFilter 包含撇号,这会关闭过滤器查询并导致错误。

有没有办法让我逃脱那个角色?我无法替换它。

最佳答案

只需将 titleFilter 字符串中的撇号(又名引号)加倍即可

dv.RowFilter = "ContentTitle = '" + titleFilter.Replace("'", "''") + "'";

关于c# - DataView RowFilter 中的撇号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16362464/

相关文章:

c# - 如何在数据访问层管理 SqlDataReader?

C# - 我怎样才能拥有一个引用任何实现一组接口(interface)的对象的类型?

c# - 需要在我的 View 中动态添加另一个条目(--Select--)到 DropDownList

c# - ASP.NET 如何在 asp 按钮单击上填充 html 表

c# - ASP.NET 图表无法在服务器上运行

c# - 从字符串中删除空白字符

c# - 在 Xamarin.iOS 中设置 RootViewController 后 NavigationController 为 null

c# - C# 编程标准中应包含哪些内容?

c# - 如何在 asp.net Visual Studio 中以 Web 表单显示图像?

asp.net - 亚音速 3 : Calling Stored Procedures as functions in ASP. 网络 4