{"Operator '=' is not defined for type 'DBNull' and type 'Double'."}

rocks_lp

Member
Joined
Dec 16, 2008
Messages
15
Programming Experience
Beginner
when a user inputs a value into a text box, i am searching that value in my dataset. although the number that i entered is in my dataset, i am getting this excemption.
please help me
 
What you should do when dealing with null values is use the 'Is DBNull.Value' because null's don't equal anything (not even 'Nothing').

So what you can do is first check that the data isn't null then check to see if the values match:
VB.NET:
If DataSetValue IsNot DBNull.Value AndAlso DataSetValue = SomeValue Then
  'Value isn't a DB Null and is equal to whatever condition(s)
End If
 
You certainly can do as JB suggests but if you're getting a value from a DataReader or a DataRow then they both have methods for detecting null values:
VB.NET:
If Not myDataReader.IsDBNull(columnIndex) AndAlso myDataReader.GetDouble(columnIndex) = myDouble Then
VB.NET:
If Not myDataRow.IsNull(columnName) AndAlso CDbl(myDataRow(columnName)) = myDouble Then
 

Latest posts

Back
Top