String.IsNullOrEmpty and Datarow.IsXnull

Posted by Jon on Stack Overflow See other posts from Stack Overflow or by Jon
Published on 2010-04-13T10:25:49Z Indexed on 2010/04/13 10:33 UTC
Read the original article Hit count: 468

Filed under:
|

How can I improve this code? What has made this long winded is the fact that I can't use string.IsNullOrEmpty on a data row and instead I have to use a dr.IsHOUSENUMBERNull method AND the string.IsNullOrEmpty to check if it is empty. Why is this? The column in the database is sometimes empty and sometimes NULL.

I'm sure this can be written better:

     If Not dr.IsHOUSENUMBERNull Then
           If Not String.IsNullOrEmpty(dr.HOUSENUMBER) Then
                sbAddress.AppendLine(dr.HOUSENUMBER + " " + dr.ADDRESS1)
           Else
                sbAddress.AppendLine(dr.ADDRESS1)
           End If   
     Else
           sbAddress.AppendLine(dr.ADDRESS1)      
     End If

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about datatable