In SQL Server you can use the IsNull()
function to check if a value is null, and if it is, return another value. Now I am wondering if there is anything similar
For working with DB Nulls, I created a bunch for my VB applications. I call them Cxxx2 as they are similar to VB's built-in Cxxx functions.
You can see them in my CLR Extensions project
http://www.codeplex.com/ClrExtensions/SourceControl/FileView.aspx?itemId=363867&changeSetId=17967
Sadly, there's no equivalent to the null coalescing operator that works with DBNull; for that, you need to use the ternary operator:
newValue = (oldValue is DBNull) ? null : oldValue;
public static T isNull<T>(this T v1, T defaultValue)
{
return v1 == null ? defaultValue : v1;
}
myValue.isNull(new MyValue())
Use the Equals method:
object value2 = null;
Console.WriteLine(object.Equals(value2,null));