Double variable inserted as 0 instead of NULL on DB

I am having an issue with a Double variable which I read from a website. ( I first read it as a String)
I have to write this variable on a DB column, (float) using Run Query.
For the cases when the variable is empty, I have written an if:
if(String.IsNullOrEmpty(readSalesIRR),nothing,Double.Parse(readSalesIRR, CultureInfo.InvariantCulture))

But in this case the value on the DB is written as 0 and not as NULL.
Apparently using NOTHING, doesn’t work for variables which are not Strings.

Is there any way to have written null on the DB?

Thank you in advance!

give a try at:

if(String.IsNullOrEmpty(readSalesIRR),DBNull.Value,Double.Parse(readSalesIRR, CultureInfo.InvariantCulture))

Hi, thanks for your reply.
I tried this solution but I get this error:

let us know which targetframework is used within your project

we did this for Legacy:

and will also find a solution for the others

I am using Windows:


the validation message about is that the IF is not returning always the same datatype
have a look here


set the variable datatype to Object for harmonization reasons. Later the correct datatype will be used as showcased within the immediate panel

if(String.IsNullOrEmpty(readSalesIRR),DBNull.Value,{Double.Parse(readSalesIRR, CultureInfo.InvariantCulture)}.Cast(Of Object).First())

a less wired alternate could look like:

if(String.IsNullOrEmpty(readSalesIRR), DBNull.Value, DirectCast(Double.Parse(readSalesIRR, CultureInfo.InvariantCulture), Object))

It worked :smiley:
Thanks a lot for your help!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.