[英]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
. 我有这行代码使用
view_1
,我正在尝试使用RowFilter
按product_name及其大小过滤datagridview。 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
. 当我尝试运行应用程序时,它会
Missing operand after '=' operator
。 So what is that missing operand? 那么缺少操作数是什么?
You have a missing white-space at
'AND
你在
'AND
缺少空格
So replace
所以更换
'AND
with
同
AND size = '" + cboSize.Text + "'";
Is size a string-column or an int-column? 大小是字符串列还是int列? 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: 甚至更好,使用
String.Format
因为其他人已经评论,因为它具有可读性:
view_1.RowFilter = string.Format("product_name = '{0}' AND size = '{1}'" , cboProduct.Text , cboSize.Text);
Write like this 写这样的
view_1.RowFilter = "product_name = '" + cboProduct.Text + "' AND size = " + cboSize.Text + "";
Missing White space problem 缺少白空间问题
Edit 编辑
You can also use string.Format
您也可以使用
string.Format
view_1.RowFilter = String.Format("product_name = '{0}' AND size = {1}", cboProduct.Text,cboSize.Text);
I don't know what is wrong I tried to filter first if the text of cboProduct
and cboSize
is empty or if no selection has been made and now it's working. 我不知
cboProduct
什么问题,如果cboProduct
和cboSize
的文本是空的,或者如果没有选择,现在它正在工作,我首先尝试过滤。 Thank you. 谢谢。 Here is the code
这是代码
if (cboProduct.Text == string.Empty || cboProduct.SelectedIndex == -1 || cboSize.Text == string.Empty || cboSize.SelectedIndex == -1)
{
view_1.RowFilter = string.Empty;
}
else
{
view_1.RowFilter = "product_name = '" + cboProduct.Text + "' AND size = " + cboSize.Text + "";
}
If the variable product_name
is having a value that contains a space then the value needs to be wrapped in square brackets in the filter expression: So,just wrap the variable product_name
by pair of square brackets like this [product_name]
如果变量
product_name
具有包含空格的值,则需要将值包装在过滤器表达式的方括号中:因此,只需将变量product_name
包装为方括号对,如[product_name]
view_1.RowFilter = "[product_name] = '" + cboProduct.Text + "' AND size = " +
cboSize.Text + "";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.