Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing operand after '=' operator

I have this line of code which uses a dataview view_1 and I'm trying to filter the datagridview by product_name and its size using the RowFilter. Here is the code:

view_1.RowFilter = "product_name = '" + cboProduct.Text + "' AND size = " + cboSize.Text + "";

And when I try to run the application it says Missing operand after '=' operator. So what is that missing operand?

like image 746
Harvey Avatar asked Oct 21 '25 04:10

Harvey


1 Answers

You have a missing white-space at 'AND

So replace

'AND 

with

' AND 

Is size a string-column or an int-column? If it's a string you need quotation marks around too:

AND size = '" + cboSize.Text + "'";

or even better, use String.Format as others have commented since it insreases readability:

view_1.RowFilter = string.Format("product_name = '{0}' AND size = '{1}'"
            , cboProduct.Text
            , cboSize.Text);
like image 101
Tim Schmelter Avatar answered Oct 23 '25 18:10

Tim Schmelter