convert 01/01/0001 to empty string

T

Tan

I am using ObjectDataSource bind to DetailView which will contain one of the
column with the value type is date. whenver the value of this column is
empty . then it will be display the date in the format ( 01/01/0001), How
can I convert it to empty string or just string?



Thank you very much

tan
 
I

Islamegy®

DateTime type Don't Allow null or empty string.. the only way i found to
workaround this is to convert it to string and check if it's 01/01/0001..
I did myDatetime Class to do this for me when i use ToString() ,
ToShortDateString(),etc...
 
J

Juan T. Llibre

Maybe 01/01/0001 is a default value assigned in the table ?

Check the table's design and see if it is a default value.
If it is a default value, change the default value to null or empty.
 
O

Otis Mukinfus

If you are using .NET 2.0 you can use System.Nullable<T>

Look up System.Nullable in the help file.

I can not inherit from DateTime, in .net 2.0 is a sealed class, any
suggestions?
Tan
Otis
 
J

Juan T. Llibre

Isn't it simpler to assume that "01/01/0001" is a default value in the
table in question, and that changing that default value to <null>
would simplify the checking/text assignment task ?

Then, checking for IsDBNull / System.DbNull is simple, or use the faster :

bool isNull = (dr[ordinal]==System.DBNull.Value);
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top