Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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)

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

Any ideas on what a "Bannon operator" is?

like image 316
Greg Bair Avatar asked Jul 14 '11 13:07

Greg Bair


3 Answers

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: ' -> ''.

like image 50
Heinzi Avatar answered Nov 09 '22 04:11

Heinzi


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

like image 33
SLaks Avatar answered Nov 09 '22 05:11

SLaks


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

like image 42
Jethro Avatar answered Nov 09 '22 04:11

Jethro