Preserving NULL values in a Double Variable

前端 未结 3 1697
眼角桃花
眼角桃花 2020-12-21 16:58

I\'m working on a vb.net application which imports from an Excel spreadsheet.

If rdr.HasRows Then
        Do While rdr.Read()
            If rdr.GetValue(0).         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-21 17:23

    You need the question mark ? to let Double (or any value type) can store null (or Nothing). E.g.:

    Dim num as Double? = Nothing
    

    Note the ? mark.

    To store in the db:

    If num Is Nothing Then
      ... System.DBNull.Value ...
    Else
      ... num ...
    End If
    

    or better:

    If num.HasValue Then
      ... System.DBNull.Value ...
    Else
      ... num.Value ...
    End If
    

提交回复
热议问题