All VB6 database-intensive applications need to handle null values in fields. No problem exists if the original VB6 code uses the IsNull method, as in this example:
If IsNull(rs("BirthDate")) Then
End If
Unfortunately, VB6 offers many other ways to work with null fields, including appending an empty string to the field value to force the conversion into string:
If rs("BirthDate") & "" = "" Then
End If
Alas, the above statement throws a runtime exception under VB.NET or C# if the field value is Null, because the concatenation operator doesn’t work with DBNull values. The VBMigrationPartner_Support.bas module includes the FixNullValue6 method, which converts Null and Empty values to the empty string and can therefore be used to solve this issue:
If FixNullValue6(rs("BirthDate")) = "" Then
End If
If the application contains hundreds or thousands of statements such as the previous ones, you need a way to post process the result of the migration and automatically insert a call to the FixNullValue6 method. This task is quite easy if we assume that the operation of appending an empty string is meaningful only for converting Null and Empty values:
Notice that this pragma accounts for both & and + concatenation operators, and also accounts for cases when vbNullString is used instead of the “” empty string constants. When converting to C#, the pragma is slightly different:
If you prefer to render these cases into VB.NET using the IsNull6 method, you can try the following set of PostProcess pragmas:
When converting to C#, the PostProcess pragmas are different:
If these pragmas don’t cover all possible cases, you can still add a pragma that inserts a call to FixNullValue6:
Here is the C# version: