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:
01015109
Views:
17
I use about 5 columns from the DataRowView to change the appearance of the ASP.NET DataGrid. Rather than keep repeating:
(decimal)drvPortfolio["EnterPrice"];
I use variables instead:
decimal enterPrice = (decimal)drvPortfolio["EnterPrice"];
then use enterPrice throughout the rest of the code. It's really more to make the code easier to read for me. I can work around it by just using:
if (drvPortfolio["ExitDateTime"] != DBNull.Value)
   ...
but it seems odd that I can't set a DateTime value to 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
Reply
Map
View

Click here to load this message in the networking platform