无法将字符串识别为有效的布尔值.如何解决此错误? [英] String was not recognized as a valid Boolean.how to solve this error?

查看:169
本文介绍了无法将字符串识别为有效的布尔值.如何解决此错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮忙吗?

在下面的编码中,我得到了以下错误"字符串未被识别为有效的布尔值",其中-"if (Convert.ToBoolean( condition = "<500"))"

Can anyone help?

In this following coding I got this Error "String was not recognized as a valid Boolean" where - " if (Convert.ToBoolean( condition = "<500"))"

public void price()
{
    if (Convert.ToBoolean( condition = "<500"))
    {
        SqlCommand cmd = new SqlCommand("select pro_img,pro_name,price from product where price='" + price_range + "' and status='A' and type='retail'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataList1.DataSource = ds;
        DataList1.DataBind();
    }

}

推荐答案

尝试更改运算符:
Try changing the operator:
if (Convert.ToBoolean( condition = "<500"))

成为

if (Convert.ToBoolean( condition == "<500"))


实际上,完全将Convert位完全转储:


In fact, dump the Convert bit altogether:

if (condition == "<500")


即使您更新后的详细信息并未提供所有详细信息.

如果您的condition 变量为int类型,则按如下所示修改您的代码.无需使用Convert.ToBoolean.
Even your updated details does not provide all the details.

If your condition variable is of int type, then modify your code as below. No need to use Convert.ToBoolean.
if (condition < 500)


否则,让我们知道什么是condition变量的类型.


Otherwise let us know, what is a Type of condition variable.


这篇关于无法将字符串识别为有效的布尔值.如何解决此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆