Preserving NULL values in a Double Variable

Posted by Sam on Stack Overflow See other posts from Stack Overflow or by Sam
Published on 2010-04-15T17:26:42Z Indexed on 2010/04/15 17:33 UTC
Read the original article Hit count: 145

Filed under:

Hi,

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).Equals(System.DBNull.Value) Then
                Return Nothing
            Else
                Return rdr.GetValue(0)
            End If
        Loop
    Else

I was using string value to store the double values and when preparing the database statement I'd use this code:

If (LastDayAverage = Nothing) Then
            command.Parameters.AddWithValue("@WF_LAST_DAY_TAG", System.DBNull.Value)
        Else
            command.Parameters.AddWithValue("@WF_LAST_DAY_TAG", Convert.ToDecimal(LastDayAverage))
        End If

I now have some data with quite a few decimal places and the data was put into the string variable in scientific notation, so this seems to be the wrong approach. It didn't seem right using the string variable to begin with.

If I use a double or decimal type variable, the blank excel values come across as 0.0.

How can I preserve the blank values?

Thanks

© Stack Overflow or respective owner

Related posts about vb.net