如何在传递给DataTable Select()的字符串中包含撇号?

时间:2011-02-05 10:41:05

标签: ado.net datatable

dt.Select(string)符号位于字符串中时,missing operand会出现错误apostrophe

解决此错误的方法是什么?或者如何处理这个错误?

1 个答案:

答案 0 :(得分:11)

String value = "Rubens' Home"; // value you want to sanitize and search
dt.Select(String.Format(
    "Location = '{0}'", value.Replace("'", "''")));