Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatable option results in "Missing operand after 's' operator" error

Tags:

c#

datatable

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?

like image 372
emrahe Avatar asked Nov 28 '22 04:11

emrahe


2 Answers

The problem is "Dyn's". Can you use \' instead of '? That apostrophe is why the problem is occurring.

like image 114
Serkan Hekimoglu Avatar answered Dec 05 '22 18:12

Serkan Hekimoglu


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.

like image 29
Mark Elliot Avatar answered Dec 05 '22 16:12

Mark Elliot