Click here to Skip to main content
15,910,886 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:


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 + "')");
Posted
Comments
Ashi0891 14-Aug-14 2:15am    
what are you actually trying to do here?
and why are you doing it this way?
Member 10891595 14-Aug-14 2:17am    
i want to check the table that are present in database or not this query return me boolan value

so i can use this boolean value in if -else control

Try this one

SQL
SELECT cast(case WHEN Exists(Select * from information_schema.tables where table_name='" + ddlCityName.Text + "')
            THEN 1 
            ELSE 0 
            END as bit)
 
Share this answer
 
v2
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.
 
Share this answer
 
Use this code I think this may help you.

C#
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 as answer if its helps you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900