Take the 2-minute tour ×

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.
   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?

share|improve this question
Obligatory xkcd reference –  dtb Jul 14 '11 at 14:01
Best question ever. –  J. Steen Jul 14 '11 at 14:01
Is userdata[1] the user's last name? Is his name "O'Bannon"? –  David Yaw Jul 14 '11 at 14:01
Ok, i'm an idiot. userData[1] is a name, userData[2] is an email address. corrected. –  Greg Bair Jul 14 '11 at 14:16
add comment

3 Answers

up vote 24 down vote accepted

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:

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

share|improve this answer
Ah yes, the infamous Bobby Tables... –  J. Steen Jul 14 '11 at 14:00
@ J. Steen: IMHO, SLaks deserve this great comment :) –  naveen Jul 14 '11 at 14:11
add comment

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

share|improve this answer
Ah yes, the infamous Bobby Tables... (added for comic relief, on request ;) –  J. Steen Jul 18 '11 at 7:46
add comment

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

share|improve this answer
add comment

Your Answer


