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.