• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

c# mysql what wrong with it

c# mysql  what wrong with it code error
MySqlConnection conDatabase = new MySqlConnection("Data Source=localhost;" +
                                       "Persist Security Info=yes;" +
                                       "UserId=tee; PWD=t579; database=ph3;");

            using (MySqlCommand cmd = new MySqlCommand("SELECT count(*) FROM `member` WHERE `tambol` LIKE '¿¿¿¿¿¿¿' ", conDatabase))

                        int count = (int)cmd.ExecuteScalar();


                    catch (MySqlException ex)

Open in new window

3 Solutions
Rajkumar GsSoftware EngineerCommented:
Query may be returning NULL
SELECT count(*) FROM `member` WHERE `tambol` LIKE '¿¿¿¿¿¿¿' "

Open in new window

Try change this query to
SELECT ISNULL(count(*), 0) FROM `member` WHERE `tambol` LIKE '¿¿¿¿¿¿¿' "

Open in new window

Try putting a break on the cmd.  When it hits that, press F10 and see if cmd is null.  If it is, you could just put in "if (cmd != null) { int count = (int)cmd.ExecuteScalar(); }".  Otherwise,  I would try what RajkumarGS said.  I am just going off what he said.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I usually debug by doing this in 2 steps:

 object res = cmd.ExecuteScalar();
 int count = (res == null || res == DBNull.Value) ? 0 : (int)res;

Open in new window

and eventually debug on "res" value to see what it is ...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now