This is a migrated thread and some comments may be shown as answers.

Report bombed when DataSource binded to IList<T> with DBNull value

4 Answers 186 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Paul Chen
Top achievements
Rank 1
Paul Chen asked on 15 Oct 2007, 04:47 PM

Hi, It is kind of hard to post all my actual codes here because I am working from rather complicated business objects. Here is a simplified model.

   public partial class ReportViewer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            IList<Order> myOrderList = GetFromBO.GetOrders();
            Report myReport = new ReportLibrary.MyOrderReport;
            myReport.DateSource = myOrderList;
            this.ReportViewer1.Report = myReport;       
        }   
    }   
 
    class GetFromBO { 
        public IList<Order> GetOrders() { 
            ILIst<Order> orderList = new List<Order>;
            Order order;           
            //fill the IList<Order> with orders
            //...      
            orderList.Add(order)
            //...          
            orderList.Add(order)
           //...
            return orderList;
        }   
    } 
   
    class Order {
      public int OrderID;
      public datetime OrderShipDate;
      public IList<OrderDetail> OrderDetails;
      ....
      }   
    }
 
    class OrderDetail { 
        public int OrderDetailID;   
        Public Item item;
        public int Quantity;
        ....
    } 
   
    class Item { 
        public int ItemID ;
        public string ItemName ;
        public datetime AvailableDate ;
        ....
    } 

The myReport will display List<Order>.OrderShipDate, as well as List<Order>.OrderDetails.Item.AvailableDate.

Here is the error message "Cannot set Column 'OrderShipDate' to be null.Please use DBNull instead". I believed it was caused by Nullable database field of [Order.OrderShipDate] or [Item.AvailableDate].

Please help if there is a way to get around this. Thanks.

4 Answers, 1 is accepted

Sort by
0
Paul Chen
Top achievements
Rank 1
answered on 15 Oct 2007, 09:05 PM
OK, I believe this is the core of the problem....
 
My business objects have translated the database DateTime field from DBNull to null, but there seems no way that I can set the Order.OrderShipDate property value back to System.DBNull.Value if it is null.

Other than giving a dummy date value to the property, is there anyway I can twick Telerik Reporting control to accept a null value? Any insights would be greatly appreicated.
0
Svetoslav
Telerik team
answered on 16 Oct 2007, 09:00 AM
Hi Paul Chen,

Yes this problem occurs when binding to business objects that expose public properties of nullable types (that is the case when using a 3rd party tool to auto generate objects for a data layer). We're already aware of this issue and it will be fixed in the next release Q3 2007 due at the mid of December. Until then there are not many ways to go. The best is to avoid using Nullable types or replace the null value with another that choose as invalid - ex. new DateTime(1900, 1, 1) will be good enough in your case. Please excuse us for the troubles caused.

I hope this information helps. Thank you.

Best wishes,
Svetoslav
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jimmy Stuart
Top achievements
Rank 1
answered on 05 Nov 2007, 11:07 PM
Can you please give us an example of how we're supposed to replace the null value and insert a dummy value?

I've tried replacing the value in the ItemDataBinding event of both the Report and DetailSection with no luck.  Each time I still get the DBNull error ("Cannot set Column 'TourTotal' to be null. Please use DBNull instead").

ALso any chance of the fix for this making it as a hotfix before mid-December?

Help!

Thanks,

Jimmy
0
Svetoslav
Telerik team
answered on 06 Nov 2007, 11:12 AM
Hi Jimmy,

I am happy to inform you that we have already fixed this issues and the fix will be part of the upcoming Q3 2007 release due in a month.

The answer to your question is not straight forward and it strongly depends on your exact case.

If you use a SQL (T-SQL) query to acquire your data you may consider using the ISNULL function like this:

    SELECT ISNULL(TourTotal, 0)
    FROM ...

In case you use business objects you possible need to rework the TourTotal property (I guess you have such) and check whether the value is null and in this case return 0:

int? tourTotal;

public int? TourTotal
{
    get
    {
        // Option 1 - do not return null values;
        // use 0 instead;
        if (this.tourTotal == null)
        {
            return 0;
        }
        return this.tourTotal;
    }
   
    set
    {
        // Option 2 - do not accept null-s
        // and assign 0 instead.
        if (value == null)
        {
            this.tourTotal = 0;
        }
        else
        {
            this.tourTotal = value;
        }
    }
}


Another possible scenario I can remember is if you are binding to a DataSet/DataTable. In this case before passing it to the report consider iterating through all rows and replace the nulls with zero.

These are some of the possible scenarios and possible solutions. However, It is up to you to choose the best according to your specific needs.

Sincerely yours,
Svetoslav
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Paul Chen
Top achievements
Rank 1
Answers by
Paul Chen
Top achievements
Rank 1
Svetoslav
Telerik team
Jimmy Stuart
Top achievements
Rank 1
Share this question
or