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!