[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

Dealing with NULL data

I have a datetime database column.  I need to deal with a possible NULL.  Here's my line of code, which I thought would do it, but I get this error message:   Public member 'ToShortDateString' on type 'DBNull' not found.

the_admin_reviewer_date = IIf(IsDBNull(Reader.Item(25)), "", Reader.Item(25).ToShortDateString)

How do I deal with a NULL data value?
0
HLRosenberger
Asked:
HLRosenberger
  • 2
1 Solution
 
wdosanjosCommented:
The IIf will call all functions involved in the expression, true part, and false part before checking the expression result.  The alternative here is to use an If statement.

If IsDBNull(Reader.Item(25)) Then
     the_admin_reviewer_date = ""
Else
     the_admin_reviewer_date =  Reader.Item(25).ToShortDateString
End If

Open in new window


More about IIf here:
http://msdn.microsoft.com/en-us/library/27ydhh0d%28VS.71%29.aspx
0
 
wdosanjosCommented:
Alternatively:

the_admin_reviewer_date = If(IsDBNull(Reader.Item(25)), "", Reader.Item(25).ToShortDateString)

Open in new window

0
 
Imran Javed ZiaCommented:
Please try this

the_admin_reviewer_date = IIf(Reader.Item(25) Is DBNull.Value, "", Convert.ToDateTime(Reader.Item(25)).ToShortDateString())

thanks
0
 
HLRosenbergerAuthor Commented:
Thanks.  You are correct - splitting it up does the trick
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now