开发者

Error "Missing operand after 'Bannon' operator" - what 'Bannon' operator is?

Working on a C# console app, I have a line:

rowsFound = tempUsers.Select("EmailAddress = '" + userData[2].ToString() + "'");

rowsFound is a DataRow[], tempUsers is a DataTable, and userData is a SqlDataReader. I had the wrong index for userData (it was 1) and I got this error:

System.Data.SyntaxErrorException was unhandled
   Message=Syntax error: Missing operand aft开发者_JAVA技巧er '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)

When I inserted the correct index (2), the error went away.

Any ideas on what a "Bannon operator" is?


That guy was probably called O'Bannon (= userData[1]), resulting in the following string:

EmailAddress = 'O'Bannon'

The following Stackoverflow question contains a guide on how to properly escape data used in DataTable.Select:

  • Correct way to escape characters in a DataTable Filter Expression

With respect to single quotes, you just need to duplicate them: ' -> ''.


userData[1].ToString() was probably something like Bobby' Bannon


Please see this link. Bannon comes from the either UserData[2].ToString()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜