Printing text if DateTime column is NULL
Posted: Wed Aug 05, 2009 12:22 pm
Hello,
Background to problem :-
We are using a SQL view as the source of our report and some of the columns are nullable DateTime fields. When we add this view as a datasource the columns in the Dictionary have a datatype of DateTime (NOT DateTime (nullable)). Anyway we can not change these datatypes because we automatically synchronize the views and the Dictionary using the Stimulsoft functions.
Problem :-
The problem is that we want to print, for example "The date is Empty" if the date is NULL, or the actual date, if one is present. I have spent some time attempting this by putting code in the GetValue event, and from what I can see as soon as I access the DateTime column it is throwing an exception, which presunably is being handled and then nothing is printed. I have tried comparing the column to null, DBNull, etc. The only solution I came up with is shown below.
try
{
e.Value = DateToStr(data.VALID_FROM);
}
catch (Exception)
{
e.Value = "The date is Empty";
}
What is the correct way to do this ?
Many thanks
Robin
Background to problem :-
We are using a SQL view as the source of our report and some of the columns are nullable DateTime fields. When we add this view as a datasource the columns in the Dictionary have a datatype of DateTime (NOT DateTime (nullable)). Anyway we can not change these datatypes because we automatically synchronize the views and the Dictionary using the Stimulsoft functions.
Problem :-
The problem is that we want to print, for example "The date is Empty" if the date is NULL, or the actual date, if one is present. I have spent some time attempting this by putting code in the GetValue event, and from what I can see as soon as I access the DateTime column it is throwing an exception, which presunably is being handled and then nothing is printed. I have tried comparing the column to null, DBNull, etc. The only solution I came up with is shown below.
try
{
e.Value = DateToStr(data.VALID_FROM);
}
catch (Exception)
{
e.Value = "The date is Empty";
}
What is the correct way to do this ?
Many thanks
Robin