Go Premium for a chance to win a PS4. Enter to Win


Date Types in VB.NET Classes

Posted on 2009-07-15
Medium Priority
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?  
Question by:dbote

Accepted Solution

bhmahler earned 2000 total points
ID: 24858974
You can try making the datatype a Nullable value

Public Property SomeDate As Nullable(Of Date)
    End Get
    Set(ByVal value As Nullable(Of Date))
    End Set
End Property

Open in new window


Author Closing Comment

ID: 31603713
This definitely works.  Thank you.
LVL 64

Expert Comment

by:Fernando Soto
ID: 24859137
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)



Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

885 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