I am getting null value in excel sheet now I want to convert in zero so I can apply if condition
Hi @Aditya10989,
You can even check if there is null or not for if condition instead of int like…
String.isNullOrEmpty(value).
Cheers.
Vashisht.
I am attaching you screen shoot my chkamt is int form if I am getting null value from excel sheet then it convert to zero if Convert.ToInt32(row.Item(21)) this is null then it show the value zero
Can you check type of the variable using row.item(21).GetType before converting to integer.
@Aditya10989
you can try below…
CheckAmt = if(String.IsNullorEmpty(row.item(21).Tostring) ,0,Cint(row.item(21).ToString))
this wont work…
because you are converting Boolean value to int…
when row.Item(21).ToString = System.DbNull
your function will always produce = 1
else
your function will always produce = 0
it wont convert row.Item(21).ToString value to Int…
and one more thing…
if you are getting check amount in decimal value, use below instead…
if(String.IsNullorEmpty(row.Tostring) ,0,Convert.ToDecimal(row.ToString))
“If” structure is the following:
if( condition, value if condition is true, value if condition is false).
so, in if(String.IsNullorEmpty(row.item(21).Tostring) ,0,Cint(row.item(21).ToString))
when String.IsNullorEmpty(row.item(21).Tostring) → string is empty
return 0
else return row.item(21) value
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.