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?
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: ' -> ''.
userData[1].ToString() was probably something like Bobby' Bannon
Please see this link. Bannon comes from the either UserData[2].ToString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With