473,324 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Handling Null Dates

Hello Everyone and thanks for your help in advance. I am developing an application that utilizes a separate class library for data access to a SQL Server database. One of the tables has several fields defined as DateTime. The data access layer exposes properties for each field in the table. In the instance of datetime fields, the class returns a property of date type. The problem occurs when one of the datetime fields is NULL, which results in a value of 12:00:00 AM being returned. I then tried the following code

If Not IsDBNull(myclass.mydate) the
myTextbox.Text = myClass.myDat
Els
mytextbox.Text = "
End I

However, it still returned the 12:00:00 AM. Is there any way around this problem other than returning a string value, that converting it is datetime functions are required? Any help would be greatly appreciated. Thanks.
Nov 22 '05 #1
3 2607
It sounds like your class is reading the value of the datetime field
and making it "12:00:00 AM". From then on, the value is not null, but
that time.

Option A: In your class, when reading the value of the datetime field
from the database, set the value to Null instead of midnight.

Option B: When reading the value of myClass.myDate, instead of
checking for DBNull, check for "12:00:00 AM". Of course, if a real
time of midnight were ever there, this would fail. I assume though
that your actual datetime would include dates, so this should work.
Just a bit kludgy.

On Sat, 28 Feb 2004 09:26:05 -0800, kmcnet
<an*******@discussions.microsoft.com> wrote:
Hello Everyone and thanks for your help in advance. I am developing an application that utilizes a separate class library for data access to a SQL Server database. One of the tables has several fields defined as DateTime. The data access layer exposes properties for each field in the table. In the instance of datetime fields, the class returns a property of date type. The problem occurs when one of the datetime fields is NULL, which results in a value of 12:00:00 AM being returned. I then tried the following code:

If Not IsDBNull(myclass.mydate) then
myTextbox.Text = myClass.myDate
Else
mytextbox.Text = ""
End If

However, it still returned the 12:00:00 AM. Is there any way around this problem other than returning a string value, that converting it is datetime functions are required? Any help would be greatly appreciated. Thanks.


Nov 22 '05 #2
Thanks Dan. That does work. However, I am not sure why it is being set to 12:00:00 am in the first place. The code I am using is as follows

To initialize the variabl

Private _HireDate As Dat

Then on the read from the database

If Not IsDBNull(myReader("HireDate")) The
_HireDate = Trim(myReader("HireDate")
End I

Finally, the property is set

'HireDat
ReadOnly Property HireDate() As Dat
Ge
Return _HireDat
End Ge
End Propert

So, I really can't figure out where the 12:00:00 am come from. Any insight?
Nov 22 '05 #3
On Sat, 28 Feb 2004 10:21:05 -0800, kmcnet <an*******@discussions.microsoft.com> wrote:

¤ Thanks Dan. That does work. However, I am not sure why it is being set to 12:00:00 am in the first place. The code I am using is as follows:
¤
¤ To initialize the variable
¤
¤ Private _HireDate As Date
¤
¤ Then on the read from the database:
¤
¤ If Not IsDBNull(myReader("HireDate")) Then
¤ _HireDate = Trim(myReader("HireDate"))
¤ End If
¤
¤ Finally, the property is set:
¤
¤ 'HireDate
¤ ReadOnly Property HireDate() As Date
¤ Get
¤ Return _HireDate
¤ End Get
¤ End Property
¤
¤ So, I really can't figure out where the 12:00:00 am come from. Any insight?

Because uninitialized dates have a default value of 1/1/0001 12:00:00 AM.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kris M | last post by:
How do i handle a null value for a date variable type. I am retrieving date data from an access database and storing the records in an array for processing. The array field has a date type and the...
3
by: kmcnet | last post by:
Hello Everyone and thanks for your help in advance. I am developing an application that utilizes a separate class library for data access to a SQL Server database. One of the tables has several...
12
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
4
by: wapsiii | last post by:
I'm unsure how best to handle dates from my webforms to my database. Often I have a textbox and a datepicker on a webform. Upon postback dates are received in string format (like DD-MM-YYYY)....
2
by: Yog | last post by:
Is there a best way to handle various formats of dates for SQL server?. The data comes in various input files with different date formats. The ParseExact function looks like an "evil" and it...
34
by: Chad | last post by:
Given the following code that achieves no useful purpose: #include <string.h> #include <stdio.h> #include <string.h> int manip(char *str) { size_t len = strlen(str)-1; if(len >= 3) {
5
by: AAJ | last post by:
Hi Does anyone know of any good publically available set of standards for managing dates when dealing with a database server (in my case SQL Server 2000 and c# VS2005). At the moment, if I...
4
by: Jeff Goodman | last post by:
If there is a better newsgroup to post this in, please let me know. I am a relatively new VB.NET/SQL 2000 programmer. I am working with data imported into SQL2K from Access. Many of the dates...
2
by: Jim Carlock | last post by:
(1) Does PHP provide any way to handle dates prior to 1980? I know there's problems with Microsoft Windows NT and all Windows NT operating systems will allow a date prior to 1980 to be placed...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.