I have a datatable and I want to filter this table with a company name. But it gave this error:
Syntax error: Missing operand after 's' operator.
My code is like this:
DataRow[] rowList = resultDt.Select(string.Format(" [{0}] = '{1}'", resultDt.Columns["Company"], "Dyn's"));
What is be the problem?
The problem is "Dyn's
". Can you use \'
instead of '
? That apostrophe is why the problem is occurring.
It's the apostrophe in the name, you need to escape it:
DataRow[] rowList = resultDt.Select(string.Format(" [{0}] = '{1}'", resultDt.Columns["Company"], "Dyn\'s"))
The issue is it's being substituted for {1}
and so the resulting string looks like 'Dyn's'
, escaping it gets you to 'Dyn\'s'
which should be okay.
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