在 C# 控制台应用程序上工作,我有一行:
rowsFound = tempUsers.Select("EmailAddress = '" + userData[2].ToString() + "'");
rowsFound
是一个DataRow[]
,tempUsers
是一个DataTable
,而userData
是一个 SqlDataReader
。 userData
的索引错误(它是 1),我得到了这个错误:
System.Data.SyntaxErrorException was unhandled
Message=Syntax error: Missing operand after 'Bannon' operator.
Source=System.Data
StackTrace:
at System.Data.ExpressionParser.Parse()
at System.Data.DataExpression..ctor(DataTable table, String expression, Type type)
at System.Data.Select..ctor(DataTable table, String filterExpression, String sort, DataViewRowState recordStates)
at System.Data.DataTable.Select(String filterExpression)
当我插入正确的索引 (2) 时,错误消失了。
关于什么是“类农运算符(operator)”有什么想法吗?
最佳答案
那个人可能叫 O'Bannon
(= userData[1]
),导致以下字符串:
EmailAddress = 'O'Bannon'
以下 Stackoverflow 问题包含有关如何正确转义 DataTable.Select
中使用的数据的指南:
关于单引号,你只需要复制它们:'
-> ''
。
关于c# - 错误 "Missing operand after ' 类农算子”—— 'Bannon' 算子是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6694315/