Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I avoide "Conversion from type 'DBNull' to type 'Double' is not valid." when there is no values in the database? I am trying to add the perticular data field using
SQl select sum (field) from tablename where condition .
but getting the error mentioned above.
Posted
Comments
Richard MacCutchan 28-Feb-14 4:34am    
You need to exclude records containing DBNull.

Depending on the type of database your querying, you could modify your query to replace any null results with 0.
... something like:

SQL
select ISNULL(sum(field),0) from tablename 
 
Share this answer
 
Comments
Ni!E$H_WAGH 28-Feb-14 4:55am    
Thank you very much .
You can use Convert.IsDBNull Method[^].
Quote:

Returns an indication whether the specified object is of type DBNull.

 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900