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 in C#.
For example, I want to do something like:
myNewValue = IsNull(myValue, new MyValue());
instead of:
if (myValue == null)
myValue = new MyValue();
myNewValue = myValue;
Thanks.
I've been using the following extension method on my DataRow types:
usage:
I'm checking for the existence of the column first because if none of query results has a non-null value for that column, the DataTable object won't even provide that column.
Use the Equals method:
You Write Two Function
They Work Very Well
Use below methods.
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