Specified cast is not valid - next case ?

2004-04-20
2004-04-21
  • Thank you to solve so quickly my problem.

    I have another "Specified cast is not valid" with ExecuteScalar for a request "SELECT COUNT(*)".

    My code was :
    return (int) BDD.ExecuteScalar("SELECT COUNT(*) FROM Jobs");

    And I have to update it like this :
    System.Decimal _dcount = (System.Decimal) BDD.ExecuteScalar("SELECT COUNT(*) FROM Feeds");
    return (int) _dcount;

    It is not very important, but perhaps it would be better to manage this in the provider ?

    Michel.

     
    • Tim McDaniel
      Tim McDaniel
      2004-04-21

      For this COUNT(*) SQL statement, SQLite returns a column type of NUMERIC, which SQLite.NET maps to Decimal.  Since NUMERIC and DECIMAL are synonymous in SQL, this mapping is by design.

      You should be able to shorten your statement a bit:
      return (int) (Decimal) BDD.ExecuteScalar("SELECT COUNT(*) FROM Jobs");