473,385 Members | 1,587 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,385 software developers and data experts.

DateTime problem

nic
hey,

I always struggle with the following:

I have an object obj with a property paydate (type = DateTime)
Now, after instantiating the object and do several things, I want too check if my paydate is still empty.
How can I do this?

I tried several things like (all with errors):
if (obj.paydate == null)
if (obj.paydate.gettype() == System.DBnull)
if (obj.paydate == 01/01/0001)
etc.....

Another question :
When I want to instantiate the object and fill it with data from an sql-query (sql-database). The value received from sql for paydate = null.
How can I test in the datareader that the received data from sql is null and so I put nothing in obj.paydate.
tkx,
Nic
Nov 16 '05 #1
2 3794
nic <ni*@discussions.microsoft.com> wrote:
I always struggle with the following:

I have an object obj with a property paydate (type = DateTime)
Now, after instantiating the object and do several things, I want too
check if my paydate is still empty.
It's not empty to start with. There's no equivalent for null for value
types. Some people choose to use DateTime.MinValue as a "special" value
equivalent to null for DateTimes. Others use a separate property to
indicate whether or not the DateTime is a "real" one.
Another question :
When I want to instantiate the object and fill it with data from an
sql-query (sql-database). The value received from sql for paydate =
null.
How can I test in the datareader that the received data from sql is
null and so I put nothing in obj.paydate.


Use the IsDbNull() in the DataReader. You'll still have to work out
what to put into paydate in that case though.

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

If you initalize the paydate as PayDate = new DateTime() in the class
constructor, you can compare paydate with DateTime.MinValue to check if it
still has the initial value. The only problem with this is that if the user
sets paydate to 01/01/0001 00:00:00, then you wont be able to detect the
changes as DateTime.MinValue is nothing but 01/01/0001 00:00:00.

Alternatively, you can maintain your own dirty flag in the set accessor
method of the paydate and check that flag to detect any changes.

For checking null, use SqlDataReader.IsDBNull()

HTH.

"nic" <ni*@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
hey,

I always struggle with the following:

I have an object obj with a property paydate (type = DateTime)
Now, after instantiating the object and do several things, I want too check
if my paydate is still empty.
How can I do this?

I tried several things like (all with errors):
if (obj.paydate == null)
if (obj.paydate.gettype() == System.DBnull)
if (obj.paydate == 01/01/0001)
etc.....

Another question :
When I want to instantiate the object and fill it with data from an
sql-query (sql-database). The value received from sql for paydate = null.
How can I test in the datareader that the received data from sql is null and
so I put nothing in obj.paydate.
tkx,
Nic

Nov 16 '05 #3

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

Similar topics

4
by: ramarnath | last post by:
Problem in sending datatime format to the .net webservice from php. description follows. I've created a .net webservice. ..Net Webservice: <WebMethod()> _ Public Function HelloDate(ByVal...
5
by: niju | last post by:
Hi there I am trying to get a single digit hour in 12-hour format with the following code. DateTime hr = DateTime.Now; string hour = hr.ToString("h"); However, I get "Input string was not in...
2
by: Lee | last post by:
Hello all, I'm trying to solve a problem with a string to datetime conversion. The problem arises when I try to convert a string from an XML doc into a .net DateTime. I'm manually creating a...
4
by: luckyabhishek | last post by:
Hi I am using a java webservice in a .NET application. The xml type of a field in this webservice is xsd:datetime. When i call the webservice from the application i get a deserialization error on...
6
by: JFieseler | last post by:
Hi all, in a huge project i have the following problem. I create an object which contains many private members (i know that this is not correct, but it is a single use migration program). The...
5
by: iulian.ilea | last post by:
Is correct to have a varchar field and insert dates of type dd/mm/yyyy into it? I choose this method because I have an application that runs on more than one server. So, if I used a datetime field...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.