armi_v
November 4, 2022, 9:47am
1
Hello,
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!
ppr
(Peter)
November 4, 2022, 9:57am
2
give a try at:
if(String.IsNullOrEmpty(readSalesIRR),DBNull.Value,Double.Parse(readSalesIRR, CultureInfo.InvariantCulture))
armi_v
November 4, 2022, 10:15am
3
ppr:
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:
ppr
(Peter)
November 4, 2022, 10:17am
4
let us know which targetframework is used within your project
we did this for Legacy:
we would recommend to check the empty cells by
isNothing(row(“GRN_DATE”) OrElse String.IsNullOrEmpty(row(“GRN_DATE”).toString.Trim)
and would replace with DBNull.Value
maybe you can quick test with a constructed dummy datarow
Kindly note:
DateTime.ParseExact(row(“GRN_DATE”).ToString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture) is parsing the string with the configured format
ToString(…) is outputting the same format which is expected for the parsing.
When the parse form…
and will also find a solution for the others
ppr
(Peter)
November 4, 2022, 10:42am
6
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))
armi_v
November 4, 2022, 11:17am
7
It worked
Thanks a lot for your help!
system
(system)
Closed
November 7, 2022, 11:18am
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.