MySQL and count(*)

  • Thread starter Thread starter Pèlerin
  • Start date Start date
P

Pèlerin

Is there a known issue with MySQL and count(*) ? Whenever i use count(*) in
a SELECT command it returns 0 rows.

Thanks
Robert
 
I've been using MySQL from almost 4 years, you can imagine how many times I
used "COUNT(*)" ... I don't remember I had any kind of problems with it???
You may need to check the following:

1. Table? empty?
2. The condition in your SELECT query? probably returns nothing
3. Access right? you may have no access rights for the database, usually
"root" user can have all sufficient rights
4. Can you run your query in your MyAdmin program? or in your MySQLFront? or
in any well-known MySQL manager?

Regards,

Veszko
 
Hi Vesko,

When I execute "SELECT * FROM employees" it works fine but when i execute
SELECT count(*) FROM employees" 0 rows are returned instead of the single
row holding the number of records. Connection is through OLEDB.

But since you've been doing it for years i'll take for granted it's
supposed to work ;)

But just in case i am doing something wrong ( i am quite new to .NET ) here
is the piece of code:


OleDbCommand oleDbCommand = GetOleDbCommand("SELECT Count(*) FROM
employee");
if (oleDbCommand != null)
{
try
{
OleDbDataReader myReader = oleDbCommand.ExecuteReader();
if (myReader.Read())
{
recCount = myReader.GetInt32(0);
}
(...)
}
finally
{
(...)
}
)


Take for granted that "GetOleDbCommand" returns a properly initialized
"OleDbCommand" object with an opened connection to the database. recCount =
0

Regards
Robert
 
what does oleDbCommand.ExecuteScalar() return?
and what if you do
object value = myReader[0];
what is stored in parameter value?
 
Back
Top