Solved

Date Types in VB.NET Classes

Posted on 2009-07-15
3
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 63

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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