I have a query that should always be returning a single int. I have now logged it returning a string entirely unrelated to what it should be.
We\'ve been ge
Is there any commonality to when it fails to return an int?
Since your query only ever returns a single column in a single row, what do you get if you use a more typesafe ExecuteReader and take the first column's value?
Is it always returning a row? If the WHERE
clause causes it to return no rows (say your parameters are not what you think they are), your ISNULL
doesn't come into effect - there are no rows at all, and ExecuteScalar is supposed to return a NULL.