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

前端 未结 9 1401
暗喜
暗喜 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:32

    The ExecuteScalar() function's return type is object, and you declare your result variable with the var keyword. That's not really a good combination, because you're putting a lot of pressure on the system to get the type inference right.

提交回复
热议问题