tags:

views:

31

answers:

4

Here is the exception:

"Conversion from string "" to type 'Double' is not valid."

Here is the line of code that that throws the exception (confirmed from stepping through in the debugger):

If LoanData.Item("ApplicationId") <> "" AndAlso LoanData.Item("ApplicationId") IsNot DBNull.Value Then

Any ideas?

+1  A: 

did you try LoanData.Item("ApplicationId").toString()?

Eclyps19
Haven't tried it yet.
Scott
Give it a shot. It should work after that.
Eclyps19
It *is* a crummy exception message. Comparing floating point values by comparing their string representation has its own major failure scenarios.
Hans Passant
+1  A: 

LoanData.Item("ApplicationId") is returning a double probably.

You're trying to compare it with a String.

If this is the problem you could just do this:

LoanData.Item("ApplicationId").ToString() <> ""

Leniel Macaferi
ApplicationId is being returned from an 'int' field on the database, the primary key of a table actually. I'm not sure how 'Double' is even in this error at all.
Scott
Try the ToString() method as I show above...
Leniel Macaferi
+1  A: 

The value stored in LoanData.Item("ApplicationId") must be of type Double.

The VB.NET compiler is letting you use the <> operator only because you must have Option Strict Off. It is assuming the value of LoanData.Item("ApplicationId") must be a String and is attempting to cast accordingly.

Since the value is not a String, you're getting an InvalidCastException.

Instead of using the <> operator, you can use Equals instead, which will result in a call to the Equals method of whatever type the value of LoanData.Item("ApplicationId") happens to have (or the Object.Equals method, if that type has not overridden it):

If Not LoanData.Item("ApplicationId").Equals("") AndAlso LoanData.Item("ApplicationId") IsNot DBNull.Value Then

This should exhibit the closest possible behavior to what you currently have without resulting in an exception.

Dan Tao
A: 

It's worth noting, btw, that VB6 would allow one to compare a double to a string directly, but this broke the transitive property of comparisons since "9" would be greater than "8Q", and "8Q" would be greater than the double 10.2 (since the double would be converted to a string in that case), but the double 10.2 would be greater than "9" (since the string would be converted to a double in that case). Eeks.

supercat