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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

date property not being set from database value

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
scm0sml
Asked:
scm0sml
  • 7
  • 4
  • 2
  • +2
1 Solution
 
MTroutwineCommented:
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
 
Asim NazirCommented:
Perhaps DateOpened  is nullable and null is stored in DB. This is why date returned is incorrect.

Asim
0
 
scm0smlAuthor Commented:
I've shown in the question that the value coming back from the db is not null?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Asim NazirCommented:
If date is nullable, you can do something like this to get default value from DB

Select
Isnull(DateOpened, GetDate())
from ...
0
 
scm0smlAuthor Commented:
THE DATE IS NOT NULL!!

It is being returned
2/28/2011 12:53:55 PM
0
 
MTroutwineCommented:
What DBMS are you pulling the data from?  SQL, Access, Oracle, etc.
0
 
scm0smlAuthor Commented:
SQL Server yeah.
0
 
scm0smlAuthor Commented:
I've got other properties working the same way elsewhere in the code.

It doesn't make any sense?!
0
 
Shahan AyyubSenior Software Engineer - iOSCommented:
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
 
scm0smlAuthor Commented:
unfortunately not :(

any other ideas?
0
 
Shahan AyyubSenior Software Engineer - iOSCommented:
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
 
Shahan AyyubSenior Software Engineer - iOSCommented:
I 'll check back in the next hour to see what happened now.
0
 
Shahan AyyubSenior Software Engineer - iOSCommented:
Hi!

Did you check that ???
0
 
scm0smlAuthor Commented:
it hasnt worked. I wouldnt have been particularly happy doing that anyway.....
0
 
scm0smlAuthor Commented:
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
 
Amandeep Singh BhullarCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now