• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • 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;");
            conDatabase.Open();





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

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


                        Console.WriteLine(count.ToString());

                    }
                    catch (MySqlException ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }

Open in new window

0
teera
Asked:
teera
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

0
 
Friman001Commented:
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.
0
 
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 ...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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