JessyRobinson1234
asked on
Conversion from string "" to type 'Double' is not valid.
I get this error only when there is no value. How can I program it where it won't throw the error in my VB code
Me.lblANR.Text = FormatNumber(rdr("Actual_N et_Revenue ").ToStrin g, 0)
Me.lblANR.Text = FormatNumber(rdr("Actual_N
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think
rdr("Actual_Net_Revenue"). ToString=" " could throw an error if the value of rdr("Actual_Net_Revenue") is dbnull
this may work better
Me.lblANR.Text = FormatNumber(IIf(String.Is NullOrEmpt y(rdr("Act ual_Net_Re venue")), 0, rdr("Actual_Net_Revenue"). ToString), 0)
rdr("Actual_Net_Revenue").
this may work better
Me.lblANR.Text = FormatNumber(IIf(String.Is
Hi vkarumbaiah,
Is that any reason you excluded my posted solution as you mentioned IIF() is work better?
Is that any reason you excluded my posted solution as you mentioned IIF() is work better?
Hi x_com
As you can see I was not excluding your solution, Instead I was clarifying and adding to it.
rdr("Actual_Net_Revenue"). ToString could throw an error if the value of rdr("Actual_Net_Revenue") is DBNull. String.IsNullOrEmpty(rdr(" Actual_Net _Revenue") ) will fix that problem.
Hope this makes it clear.
As you can see I was not excluding your solution, Instead I was clarifying and adding to it.
rdr("Actual_Net_Revenue").
Hope this makes it clear.
Hi vkarumbaiah,
Ok, understood but i though should have points splits for the assistance. FYI, if you put .ToString() for the value that returned from db, you can bypass the DBNULL problem since it already converted to string type.
http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx.
Anyway, i'm glad you resolved your glitches here. Cheers.
Ok, understood but i though should have points splits for the assistance. FYI, if you put .ToString() for the value that returned from db, you can bypass the DBNULL problem since it already converted to string type.
http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx.
Anyway, i'm glad you resolved your glitches here. Cheers.
>>..How can I program it where it won't throw the error in my VB code
Alternatively, you can use IIF() function.
http://msdn.microsoft.com/en-us/library/27ydhh0d(vs.71).aspx
eg:
Me.lblANR.Text = FormatNumber(IIF(rdr("Actu