Home Forums Reporting Services Reporting Services Is Nothing vs = Nothing RE: Is Nothing vs = Nothing<!-- 864 --><!-- 864 -->

  • When checking value or reference types, I've gotten better use out of the basic comparison operators, especially "=". You can test this with any of the nullable types in SSRS pretty quickly. They work the same as the Is, IsNot, and Not(<expression> Is <value>) operators, and have the added advantage of being able to catch the default values for the type as well as null. So, for instance, for an integer (nullable) value, = Nothing will catch when the value is null or 0. The same is true for all of the basic types that can be associated with the parameters, though I haven't figured out (or needed) the default value for the DateTime type yet. I came across this when trying to check a string value for Nothing, and when the string was the empty string, Is Nothing failed. This makes sense, but wasn't what I was hoping for. You can see an example of this on the same page that has the quote

    "When checking whether a reference (or nullable value type) variable is null, do not use = Nothing or <> Nothing. Always use Is Nothing or IsNot Nothing."

    Here's how that example reads,

    "For strings in Visual Basic, the empty string equals Nothing. Therefore, "" = Nothing is true."

    You'll find that written one line below the first quote:)