Solved

date property not being set from database value

Posted on 2011-03-02
17
334 Views
Last Modified: 2012-05-11
I have the following code:
.DateOpened = CDate(datarow.Item("DateOpened"))
.DateResolved = CDate(datarow.Item("DateResolved"))

The value of datarow.Item("DateOpened") = 2/28/2011 12:53:55 PM
The value of DateOpened = #12:00:00 AM#

How can that be?

The properties are show below.

The fields in the db are DateTime.

Can anyone see what is going on here?
Public Property DateResolved() As Date
        Get
            Return _dtDateResolved
        End Get
        Set(ByVal value As Date)
            value = _dtDateResolved
        End Set
    End Property

    Public Property DateOpened() As Date
        Get
            Return _dtDateOpened
        End Get
        Set(ByVal value As Date)
            value = _dtDateOpened
        End Set
    End Property

Open in new window

0
Comment
Question by:scm0sml
[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
  • 7
  • 4
  • 2
  • +2
17 Comments
 
LVL 3

Expert Comment

by:MTroutwine
ID: 35016721
Hi,

Are you sure you are getting a value back from the database that isn't null?  The #12:00:00 AM# would indicate a null value was returned.

Take a look at this article, if you haven't already: http://vbnotebookfor.net/2007/09/27/introduction-to-nullable-types-in-vbnet/

0
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35016725
Perhaps DateOpened  is nullable and null is stored in DB. This is why date returned is incorrect.

Asim
0
 

Author Comment

by:scm0sml
ID: 35016865
I've shown in the question that the value coming back from the db is not null?
0
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.

 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35016925
If date is nullable, you can do something like this to get default value from DB

Select
Isnull(DateOpened, GetDate())
from ...
0
 

Author Comment

by:scm0sml
ID: 35016942
THE DATE IS NOT NULL!!

It is being returned
2/28/2011 12:53:55 PM
0
 
LVL 3

Expert Comment

by:MTroutwine
ID: 35017304
What DBMS are you pulling the data from?  SQL, Access, Oracle, etc.
0
 

Author Comment

by:scm0sml
ID: 35017326
SQL Server yeah.
0
 

Author Comment

by:scm0sml
ID: 35017330
I've got other properties working the same way elsewhere in the code.

It doesn't make any sense?!
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 35025844
Hi!

Does it worked for you:

    Public Property DateResolved() As DateTime
        Get
            Return _dtDateResolved
        End Get
        Set(ByVal value As Date)
            value = _dtDateResolved
        End Set
    End Property

    Public Property DateOpened() As DateTime
        Get
            Return _dtDateOpened
        End Get
        Set(ByVal value As Date)
            value = _dtDateOpened
        End Set
    End Property

Open in new window


I hope so changing every "Date" to "DateTime" can resolve the issue.
0
 

Author Comment

by:scm0sml
ID: 35026402
unfortunately not :(

any other ideas?
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 35026419
did you tried like this:
        Dim s As String = DataRow.Item("DateOpened").ToString
        Dim dt As DateTime = Convert.ToDateTime(s)

Open in new window

0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 35026434
I 'll check back in the next hour to see what happened now.
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 35027409
Hi!

Did you check that ???
0
 

Author Comment

by:scm0sml
ID: 35027445
it hasnt worked. I wouldnt have been particularly happy doing that anyway.....
0
 

Accepted Solution

by:
scm0sml earned 0 total points
ID: 35027706
Right I have found the problem and I deserve to be sacked......but tut tut experts!!

Spot the mistake in my property!!!

Do we think this:
Set(ByVal value As Date)
            value = _dtDateResolved
        End Set

 should be this:??!!
Set(ByVal value As Date)
            _dtDateResolved = value
        End Set

Im such an idiot!!!!
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 35913609
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
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

Suggested Solutions

Title # Comments Views Activity
Create a Dropdown list with sub group 10 43
Suppress if value zero or NULL in crystal report 2 43
Datagridview column resizing 8 28
EMAIL RANGES BASED ON CURRENT TIME 12 40
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 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