Click here to Skip to main content
14,326,017 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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)
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

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

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100