Hello to all,

Just want to hear your ideas on which of the following code is more efficient.

VB Code:
  1. Dim TotalUnits as Double
  2.  
  3. ' some codes here ...
  4.  
  5. Try
  6.    Units += ds.Tables(0).Rows(i).Item("UNITS")
  7. Catch ex As Exception
  8.    ' Set Units to zero if error occur.
  9.    Units = 0
  10. Finally
  11.    TotalUnits += Units
  12. End Try

or using if statement.

VB Code:
  1. ' Check if the column UNITS is NULL
  2. If IsDBNull(ds.Tables(0).Rows(i).Item("UNITS")) Then
  3.    Units = 0
  4. Else
  5.    Units = ds.Tables(0).Rows(i).Item("UNITS")
  6. End If
  7. ' Add to TotalUnits variable.
  8. TotalUnits += Units

Thanks.