Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Question

Status
Not open for further replies.

quinnipiac0807

Programmer
Oct 25, 2004
38
US
I have a class that calls a date out of my database. If there's no date in the database I want the field to be blank, but if it's blank it puts 01/01/01 in the field. This is how I'm evaluating it.

if(dr["EstCompDate"].ToString() != String.Empty)
t.dtEstCompDate = Convert.ToDateTime(DateTime.Parse
(dr ["EstCompDate"].ToString()).ToShortDateString());

 
You might try this instead:

Code:
if (!dr.IsDBNull(dr.GetOrdinal("EstCompDate")))

Either way, I would verify that dr["EstCompDate"].ToString() really returns String.Empty for fields that have no date.

This sort of behavior can depend on the DBMS and the connector used.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top