Why is my SqlCommand returning a string when it should be an int?

前端 未结 9 1328
暗喜
暗喜 2020-12-29 17:06

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

9条回答
  •  时光说笑
    2020-12-29 17:33

    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.

提交回复
热议问题