View Single Post
  #1 (permalink)  
Old January 15th, 2004, 08:49 AM
jaucourt jaucourt is offline
Friend of Wrox
 
Join Date: Jul 2003
Location: York, , United Kingdom.
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default Dealing with DBNull

I'm currently building an object that receives values from a datareader - therefore my code looks a bit like this

Do while dr.Read
   With myobj
      .Prop1 = dr("Field1")
   End With
Loop

Now this obviously raises errors when we get null values, so I changed my code to the following;

Do while dr.Read
   With myobj
      .Prop1 = IIF(IsDBNull(dr("Field1")), "", dr("Field1"))
   End With
Loop

Whilst this works, it's not very elegant. I can create my own function where you passed in a value and it returns either the value or a zero length string. However, I wondered if there was a native vb.net command that would do something similar.