DateTime column: why dictionary type is not "datetime (nullable)"?

Stimulsoft Reports.NET discussion
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

DateTime column: why dictionary type is not "datetime (nullable)"?

Post by Fabio Pagano »

In Vs2005 I have a datatable with a datetime column. The column's ".AllowDBNull" property is true.

If a pass this datatable (regdata) to a report for designing, in dictionary i see that the column is "datetime" and not "datetime (nullable)" (i expected the nullable one).

This leads me to a problem: if the type in the dictionary is "datetime" (and not "datetime (nullable)") and i design this column using the default datetime format (the first one with an asterisk), when the value of the datetime column is null i don't see the empty field (i expected to see it empty) but i see "01/01/0001".

The question: why, though datatable column's "AllowDBNull" property is true, the column is created in dictionary as "datetime" and not "datetime (nullable)"?

Thanks.
Guest
Posts: 182
Joined: Tue Jun 06, 2006 8:04 am

DateTime column: why dictionary type is not "datetime (nullable)"?

Post by Guest »

Unfortunately, we can't resolve this issue, because we use the types of ADO.NET and it haven't datetime(nullable) type.

Thank you.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

DateTime column: why dictionary type is not "datetime (nullable)"?

Post by Fabio Pagano »

This means that i can't print an empty field when the date is null? Is there any workaround you can suggest?

Thanks.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

DateTime column: why dictionary type is not "datetime (nullable)"?

Post by Fabio Pagano »

Unfortunately, we can't resolve this issue, because we use the types of ADO.NET and it haven't datetime(nullable) type.
But in designer i see type "datetime (nullable)" in the column:

Image

If i set this, all works fine (when date is null the field is left blank) but if i leave the default "datetime" (taken from the datatable passed in regdata, though datecolumn.AllowDBNull is "True"), when the date is null it prints "01/01/0001".

Anyway, while waiting for the answer, i was thinking for a workaround: after "regdata" i could iterate through all columns in dictionary's datasource and, when i find a column with "datetime" type, force it with "datetime (nullable)" type. Is it possible?

Thanks.
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

DateTime column: why dictionary type is not "datetime (nullable)"?

Post by Brendan »

What happens when you try this piece of code in your application?

Code: Select all

        Dim tableDate As New DataTable("DateTable")

        tableDate.Columns.Add("ID", GetType(Integer))
        tableDate.Columns.Add("NullDate", GetType(DateTime)).AllowDBNull = True

        tableDate.Rows.Add(1, DateTime.Now)
        tableDate.Rows.Add(2, DateTime.Now)
        tableDate.Rows.Add(3, DateTime.Now)
        tableDate.Rows.Add(4, DBNull.Value)
        tableDate.Rows.Add(5, DBNull.Value)
        tableDate.Rows.Add(6, DateTime.Now)

        Dim report As New Stimulsoft.Report.StiReport()
        report.RegData("MyData", tableDate)
        report.Design()
when the Designer loads just drag the Datasource onto the empty page with the 2 columns and do a preview. Does it render empty DateTime fields or "01/01/0001"

For me null dates in my datatables have always shown as empty fields.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

DateTime column: why dictionary type is not "datetime (nullable)"?

Post by Fabio Pagano »

Brendan, with your suggestion i think i have found the problem: it happens only if report scripting language is VB (i use that).

To your code:

Code: Select all

Dim report As New Stimulsoft.Report.StiReport()
        report.RegData("MyData", tableDate)
        report.Design()
add the following line after report variable declaration:

Code: Select all

report.ScriptLanguage = Stimulsoft.Report.StiReportLanguageType.VB
You'll see the problem: all null dates are printed as "01/01/0001".

I'm using released version 2007.2 for Vs2005.

Thank you very much Brendan, waiting for a fix if this possible bug is confirmed.
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

DateTime column: why dictionary type is not "datetime (nullable)"?

Post by Brendan »

In this case try setting the property of the report "ConvertNulls" to false.

The CType function in VB seems to return a DateTime of 1/1/1 if you specify a null value or "Nothing" for the expression.
The CType function does not exist in C# so a direct cast is done instead and fails when the value is null.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

DateTime column: why dictionary type is not "datetime (nullable)"?

Post by Fabio Pagano »

That makes sense to all, and works.

Thanks to all.
vineet
Posts: 69
Joined: Fri Nov 10, 2017 3:12 am

Re: DateTime column: why dictionary type is not "datetime (n

Post by vineet »

Sorry for bringing this discussion up again!

I am on 2017.2.3.

When I try calling RegData for my business object, the double? is not converted to "double (nullable)", instead, it remains double. This causes a confusion for us to know whether the data was actually 0 or was null.

Can you please help?

Cheers
Vineet
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: DateTime column: why dictionary type is not "datetime (n

Post by HighAley »

Hello, Vineet.

ADO.NET does not support nullable types.
Please, try to use the RegBusinessObject() method.

Thank you.
Post Reply