Solved

Date Types in VB.NET Classes

Posted on 2009-07-15
3
357 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
ID: 24858974
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
ID: 31603713
This definitely works.  Thank you.
0
 
LVL 62

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)

Fernando

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

816 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

12 Experts available now in Live!

Get 1:1 Help Now