It is hard to be OO when using a datetime object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
BillG said:
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.
 
Bill
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top