3

I am pulling data from SQL into DataTables using the following query:

Select * FROM [dbname].INFORMATION_SCHEMA.COLUMNS 

I am comparing values from two DataTables using the following code:

If dtSource(iRow)(3) <> dtTarget(i)(3) Then
     'make moves
End If

I get the following error: Operator '<>' is not defined for type 'DBNull' and type 'DBNull'.

It is throwing the exception when comparing the COLUMN_DEFAULT column from INFORMATION_SCHEMA.COLUMNS, which has NULL values in it.

The way I'm handling this right now is by checking if there are any null values before comparing them:

If IsDBNull(dtSource(iRow)(3)) OR IsDBNull(dtTarget(i)(3)) Then 
     If (IsDBNull(dtSource(iRow)(3)) And NOT IsDBNull(dtTarget(i)(3))) OR viceversa.. Then 
          'make moves 
     End If
Else 
     If dtSource(iRow)(3) <> dtTarget(i)(3) Then
         'make moves
    End If
End If

I feel like there has to be a better way to do this, but I'm stuck on this. Any help is appreciated!

1 Answer 1

3

Try :

   If Not IsDBNull(dtSource(iRow)(3)) AndAlso Not IsDBNull(dtTarget(iRow)(3)) AndAlso dtSource(iRow)(3) <> dtTarget(i)(3) Then
            'make moves 
        ElseIf IsDBNull(dtSource(iRow)(3)) Or IsDBNull(dtTarget(iRow)(3)) Then
            'make moves 
        Else
            'Failure
        End If
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.