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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with null dates

Status
Not open for further replies.

raphael232

Programmer
Jun 9, 2006
51
0
0
GB
Hi, i'm having trouble dealing with null dates. For example first i pass my date as a string to my business layer. Then before i do my update i do the following to my date:

Code:
If inputDate <> "" Then inputDate = DateTime.Parse(inputDate) Else inputDate = Nothing

I was hoping if the string wasn't blank it would pass a date and if it was it would pass null. However this does not work.

Also i have another scenario when instead of a string i have a date already parsed. I tried directly updating from this but it did not like it when the type was value was type DBNull. Therefore i added:

Code:
If document.InputDate.GetType Is DBNull.Value Then inputDate = Nothing Else inputDate = document.InputDate

before the update but this returns an exception and the update is not carried out.

Appreciate if someone could help.

Thanks
 
first i pass my date as a string to my business layer
Why pass it as a String in the first place?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I simplified the above bit of code but i actually pass the hour minute and second as strings from DropDownList controls aswell and then parse the date.
 
Yes, but what I mean is why are you passing the anything as a String (why not check it and pass it as a date from the page)?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi problem solved. Nullable types was the answer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top