473,403 Members | 2,359 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,403 software developers and data experts.

It is hard to be OO when using a datetime object

I have a class that has as a member a datetime (birthdate). I try to
retrieve a value from a table.

Member.Birthdate = dsData.Tables(0).rows(0)("BirthDate")

works fine except when the birthdate in the table is null

so

If dsData.Tables(0).rows(0)("BirthDate") is DBNull.Value then
Member.BirthDate = ????????

I don't want to set the birthdate to the minvalue. I want it to be blank.
But a datetime will not allow a blank.

So what do I do?
Jul 21 '05 #1
5 1079
Bill

What is this for type of value
Member.BirthDate

Cor
Jul 21 '05 #2
DateTime

"Cor Ligthert" wrote:
Bill

What is this for type of value
Member.BirthDate

Cor

Jul 21 '05 #3
BillG <Bi***@discussions.microsoft.com> wrote:
I have a class that has as a member a datetime (birthdate). I try to
retrieve a value from a table.

Member.Birthdate = dsData.Tables(0).rows(0)("BirthDate")

works fine except when the birthdate in the table is null

so

If dsData.Tables(0).rows(0)("BirthDate") is DBNull.Value then
Member.BirthDate = ????????

I don't want to set the birthdate to the minvalue. I want it to be blank.
But a datetime will not allow a blank.

So what do I do?


Well, you could easily write your own reference type which just
encapsulates DateTime.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
Bill
DateTime

That is not a type that you can show, you have for that always to convert it
to a string, therefore it is in my opinion not from any importancy what the
nothing/null format is.

Just my thought,

Cor
Jul 21 '05 #5
Cor Ligthert <no************@planet.nl> wrote:
DateTime
That is not a type that you can show, you have for that always to convert it
to a string, therefore it is in my opinion not from any importancy what the
nothing/null format is.


The best time to change things into a display format is just before you
want to display them though - that way you don't have to parse and
reformat the data every time you want to change or manipulate it.

Of course, in .NET 2.0 this will all be solved using nullable types.
Until then, I believe that using a class which just contains a DateTime
would be the best bet.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #6

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

Similar topics

4
by: Flare | last post by:
OK. I'll try explain my problem so simple as possible. I have to send a complex data type to a WebService from a Asp.net webapplication. My Data type look like this. (A class with a porperty)...
0
by: CW | last post by:
I get this FieldCount error when I attempt to bind a datagrid with a dataset, not a datareader object. The code snippet is as belows: 'PopulateForm called in Page Load event Private Sub...
22
by: M K | last post by:
Heres my SP: ( i am trying to add more than 1 field but get the same error no matter how many i try to add, i thought i would try to insert the primary key only and work up from there but the...
5
by: BillG | last post by:
I have a class that has as a member a datetime (birthdate). I try to retrieve a value from a table. Member.Birthdate = dsData.Tables(0).rows(0)("BirthDate") works fine except when the...
0
by: Buddy Home | last post by:
There is two examples of code. Example 1. Send and Receive within the same process. Put this code in a console app called SendAndReceive and run the code. using System; using...
23
by: Rotsey | last post by:
Hi, I am writing an app that scans hard drives and logs info about every fine on the drive. The first iteration of my code used a class and a generic list to store the data and rhis took...
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.