Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with DateTime and NULL columns in ADO.NET
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 1.1
Database:
MS SQL Server
Miscellaneous
Thread ID:
01015071
Message ID:
01015140
Views:
24
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
Chris McCandless
Red Sky Software
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform