SqlParameter with default value set to 0 doesn't work as expected

后端 未结 2 1633
醉酒成梦
醉酒成梦 2020-12-29 21:41

I was doing something like this:

SqlParameter param = new SqlParameter(\"@Param\", 0) { SqlDbType = SqlDbType.Int };

private void TestParam(SqlParameter par         


        
2条回答
  •  时光说笑
    2020-12-29 22:25

    The 0 you are passing in is the type, not the value. 0 literals (and constant values) are allowed for any enum type - meaning the 0 of the underlying enum type, and are a better "match" than object, since it doesn't need boxing.

    Personally, I would use;

    Value = 0
    

    perhaps in the object initializer.

提交回复
热议问题