转换后我有以下错误 [英] I Have Following Error When I Converting Following

查看:52
本文介绍了转换后我有以下错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当我执行以下代码时出现以下错误请帮我缩短这些









错误::::::字符串未被识别为有效的布尔值。





我的代码是



bool value =转换。 ToBoolean(select EXISTS(select * from information_schema.tables where table_schema ='public'和table_name ='+ ddlCityName.Text +'));



when i am executing the following code i got following error please help me to short these




ERROR::::::"String was not recognized as a valid Boolean."


my code is that

bool value = Convert.ToBoolean("select EXISTS(Select * from information_schema.tables where table_schema='public' and table_name='" + ddlCityName.Text + "')");

推荐答案

试试这个



Try this one

SELECT cast(case WHEN Exists(Select * from information_schema.tables where table_name='" + ddlCityName.Text + "')
            THEN 1 
            ELSE 0 
            END as bit)


好吧,看看:你创建的文本一个SQL查询。

下一步是什么?

你必须将查询发送到数据库以从数据库中检索结果。

只有这样才能将数据库中的结果转换为布尔变量。
Well, look: You create the text of an SQL query.
What's the next step then?
You have to send the query to the database to retrieve the result from the database.
And only then can you convert the result from the database to the Boolean variable.


使用此代码我认为这可能会对您有所帮助。



Use this code I think this may help you.

string str="select EXISTS(Select * from information_schema.tables where table_schema='public' and table_name='" + ddlCityName.Text + "')"
 SqlCommand cmd = new SqlCommand(str, con);
 SqlDataAdapter da = new SqlDataAdapter(cmd);
 DataSet ds = new DataSet();
 da.Fill(ds);
int val=(convert.toint32(ds.tables[0].row[0][0]);
bool value = Convert.ToBoolean(val);





select作为答案,如果它可以帮助你。



select as answer if its helps you.


这篇关于转换后我有以下错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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