cmd.Parameters.AddWithValue nullable int

后端 未结 3 1621
后悔当初
后悔当初 2021-01-25 08:07

In my data layer class, I initialize a parameter like so:

private int? _DependencyID;

public int? DependencyID
{ get {return _DependencyID;} set {_DependencyID          


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-25 09:05

    AFAIC, ADO.NET/SQL don't support nullable types this way.

    The last example looks closest to correct to me. What kind of issues are you having with it? If you are just getting a compile error related to types, type cast your value to object:

    (object)DependencyID.Value;
    

    Since both values on either side of : must be of the same type.

提交回复
热议问题