Custom Search

Friday, November 28, 2008

Hanlde Adonet Null Value Using VB.Net

If you try the old fashioned way of checking for null:

If IsNull(rsCompany("Name")) Then

Visual Studio will tell you that IsNull is not supported and to use DBNull instead. At first I thought this was really nice. However, when I tried to do:

If rscompany("Name") = DBNull Then

I got an error about assignments not allowed to a type! What was I to do?

The Visual Studio help was its usual cryptic self ("The DBNull class is for handling NULL values"...accurate by not alot of help). After some fumbling around, I stumbled on the answer, and thought I'd share it to hopefully save someone 5 minutes of having to research it:

If rsCompany("Name") is DBNull.Value then

No comments: