Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error: Missing operand before '=' operator

Tags:

c#

asp.net

I have code like this:

DataRow[] drClaimCPT;
drClaimCPT = dtCpt.Select("CLAIM_NUMBER == " + claimNo + "");

When I run, I got an error:

Syntax error: Missing operand before '=' operator.

What did I do wrong?

like image 497
Sharon Avatar asked Feb 13 '14 09:02

Sharon


3 Answers

This should work for you if type is integer:

drClaimCPT = dtCpt.Select("CLAIM_NUMBER = " + claimNo + "");

for string:

drClaimCPT = dtCpt.Select("CLAIM_NUMBER = '" + claimNo + "'");
like image 62
Sadique Avatar answered Sep 27 '22 17:09

Sadique


I assume your claimNo is number, the right syntax is;

dtCpt.Select("CLAIM_NUMBER = " + claimNo + "");

DataTable.Select method uses same rules with DataColumn.Expression property by the way.

If your claimNo is a string, you should use single quotes with it.

dtCpt.Select("CLAIM_NUMBER = 'claimNo'");

From documentation;

User-Defined Values

User-defined values may be used within expressions to be compared with column values. String values should be enclosed within single quotation marks

like image 35
Soner Gönül Avatar answered Sep 27 '22 17:09

Soner Gönül


Your actual issue was using double '=' - that is the coding equals - rememebr it is SQL equals - so only it should be "CLAIM_NUMBER = claimNo" , not "CLAIM_NUMBER == claimNo".

like image 38
Ryno Potgieter Avatar answered Sep 27 '22 18:09

Ryno Potgieter