Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with DateTime and NULL columns in ADO.NET
Message
From
17/05/2005 20:30:06
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 1.1
Database:
MS SQL Server
Miscellaneous
Thread ID:
01015071
Message ID:
01015151
Views:
23
Good going, Chris!! I guess my head wasn't screwed on correctly this afternoon ... dunno how I missed this (I know I knew it, just didn't remember it)! You may give Kevin and I 50 lashes!! <g>

~~Bonnie

>I think I found the solution. I have to use the SqlDateTime class in the System.Data.SqlTypes namespace:
>
>
>DateTime exitDateTime;
>					
>if (drvPortfolio["ExitDateTime"] != DBNull.Value)
>   exitDateTime = (DateTime)drvPortfolio["ExitDateTime"];
>else
>   exitDateTime = (DateTime)SqlDateTime.Null;
>
>
>>I've been talking to Bonnie on this one, because I didn't have an answer beyond a workaround. We were curious what the variable was being used for, since you mentioned you're using some type of grid. However, if you're using a datetime picker, then that might affect what you do, since a datetime picker can't use a null date.
>>
>>At any rate, the only workaround I can think of is to come up with a 'fake date' in the past, one that would never normally be assigned.
>>
>>You can use this fake date as a comparison in subsequent lines of code, like whether to display something, whether to assign a stored procedure parameter, etc.
>>
>>If either bonnie or myself comes up with something better, we'll post something, but for now, using a fake date is all we can really think of.
>>
>>Kevin
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform