Checking if OracleParameter.Value is Null without doing ToString conversion

Viewed 976

I have a stored procedure which has some OUT parameters. On the .NET side I'm perplexed about how to check if the parameter is null before converting it to a .NET Double?. I've done this sort of thing a lot before across several different projects and I've never encountered this issue before...

This is every combination I've tried:

Command.Parameters.Add("PparStsValue", OracleDbType.Decimal).Direction = ParameterDirection.Output

PparStsValue = If(IsDBNull(Command.Parameters("PparStsValue").Value) OrElse
                  IsNothing(Command.Parameters("PparStsValue").Value) OrElse
                  Command.Parameters("PparStsValue").Value.ToString = "",
               Nothing,
               CDbl(Command.Parameters("PparStsValue").Value.ToString))

There is one other thing I've done which does work, but it just seems ridiculous which is to check:

Command.Parameters("PparStsValue").Value.ToString = "null"

This evaluates to True and therefore I can identify nulls... But why does a null value convert to the string "null"? That seems so inconsistent with everything else which usually converts to "".

That aside, the main question is why don't either IsDBNull and IsNothing return true?

1 Answers

When using ODP your parameter does not automatically return CLR type but rather oracle type. So the way to do it for numeric OracleParameter is this

Dim oraDec as OracleDecimal = 
    DirectCast(Command.Parameters("PparStsValue").Value, OracleDecimal)

Dim dbl as Double
If Not oraDec.IsNull Then 
    dbl = Convert.ToDouble(oraDec.Value)
End If
Related