Saturday, 31 January 2009

Testing for Database Nulls in C#

Things I always forget

  1. Mother’s Day (sorry mum)

  2. My mobile phone telephone number

  3. The 7 times table

  4. How to test for Database nulls

There’s not much hope for the first three – however maybe a quick blog might help with the last one

How I always try to test for database nulls


If(drDataRow["FieldName"] == null)

{

//Nope this never works. I won’t hit this

}

How I should test for database nulls


If(drDataRow["FieldName"] is DBNull)

{

//It works! Shirt off and do the victory dance

}

Now if I can just work on those times tables ………

No comments: