Solved

Date Types in VB.NET Classes

Posted on 2009-07-15
3
352 Views
Last Modified: 2012-06-27
I have a class in VB.NET 2008.  I have date types that are not always assigned a value. Nulls from the database.  However, when I load the data into my class VB assigns a default date.  Is this default assignment avoidable?  
0
Comment
Question by:dbote
3 Comments
 
LVL 8

Accepted Solution

by:
bhmahler earned 500 total points
Comment Utility
You can try making the datatype a Nullable value
ie


Public Property SomeDate As Nullable(Of Date)

    Get
 

    End Get

    Set(ByVal value As Nullable(Of Date))
 

    End Set

End Property

Open in new window

0
 
LVL 1

Author Closing Comment

by:dbote
Comment Utility
This definitely works.  Thank you.
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Hi dbote;

Seeming you are using VS 2008 you can try making the Date data type a Nullable type as follows:

The following three statements are equivalent:

Dim dt? As DateTime
Dim dt As DateTime?
Dim dt As Nullable(Of DateTime)

Fernando

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now