NullSafe Functions: Ensuring Safe Variables
Author:
Rob Walling
Values retrieved from DataSets, ViewState, Session State, or any number of other storage mechanisms can cause errors if they comes back as DBNull or Nothing. As an example, let's say you want to retrieve a String from a DataSet. Typically, you begin by checking if the value is DBNull.Value, then casting the value to a String (if you code with Option Strict On), then checking if it's Nothing, then trimming it. A similar process applies when retrieving a String from ViewState and Session State. In this article Rob Walling offers a few functions that ensure variables returned from DataSets, ViewState, Session State, or Functions won't break your code.
More Tutorials
|