What data type does the SQLCommand method ExecuteScalar() return?

后端 未结 3 1065
温柔的废话
温柔的废话 2021-01-18 16:08

In SQL Server, ID is a not null integer, and an identity.

When I run the following code, I get an InvalidCastException on the last line:

SqlCommand         


        
3条回答
  •  一生所求
    2021-01-18 16:19

    It's probably returning a boxed instance of a different numeric type, such as long.
    A boxed long cannot be converted to int.

    You can call GetType() on the return value to see what type it really is.

提交回复
热议问题