.Net框架DataTable.Select(String)方法当过滤器表达式包含“或” [英] .Net Framework DataTable.Select(String) method when the filter expression contains ' or "

查看:542
本文介绍了.Net框架DataTable.Select(String)方法当过滤器表达式包含“或”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.Net Web应用程序中,我在许多地方使用了公共DataRow [] Select(string filterExpression)方法。由于最后一刻的更改字符如和现在是有效的输入。我有什么选择,是否有一种方法以适当的方式更改filterExpression,并仍然保留在datatable上的Select功能,我可以切换到LINQ

In a .Net web application I use the public DataRow[] Select(string filterExpression) method in many places. Due to a last minute change characters such as ' and " are now valid input. What options do I have, is there a way to change the filterExpression in an adequate way and still preserve the Select functionality on the datatable, can I switch to LINQ?

推荐答案

将表达式文字中的单引号(')翻译成两倍:''

Escape the single quote (') in an expression literal by doubling it: ''

不需要在字符串文字中转义双引号()。字符串字面量由单引号绑定,因此双引号只需要标准的C#转义:\(如果在以@符号开头的逐字字符串中为)

No need to escape the double quote (") within a string literal. String literals are bound by single quotes, so the double quote need only be standard C# escaped: \" (or "" if within a verbatim string starting with the @ symbol)

有关详细信息,请参阅此链接

See this link for more information.

这篇关于.Net框架DataTable.Select(String)方法当过滤器表达式包含“或”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆