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

data source: Object reference not set to an instance of an object.

5 Answers 461 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gersh
Top achievements
Rank 2
Gersh asked on 03 Jul 2012, 05:27 PM
I'm using Q2 2012 of Telerik reporting. I need to use the NeedDataSource event to populate my subreports. My subreports are populated by objects that inherit Reporting.Report. When I run the report, I get this error

An error has occurred while processsing Report 'Group' (my object)
An error has occurred while resolving  '' data source: Object reference not set to an instance of an object.

this is my needDataSource
protected void needDataSource(object sender, EventArgs e)
            {
                Telerik.Reporting.Processing.ReportItemBase subreport = sender as Telerik.Reporting.Processing.ReportItemBase;
                if (this.DataSource != null)
                {
                    ods = new ObjectDataSource();
                    ods.DataSource = this.DataSource;
                    ods.DataMember = groupid;
                    ods.Parameters.Add(new ObjectDataSourceParameter(groupid));
                    subreport.Report.DataSource = ods;
                }              
            }

Thanks in advance!
Gersh

5 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 05 Jul 2012, 04:00 PM
Hello Gersh,

It is not good idea to set data source of other data items (be it subreport, table or chart) in the NeedDataSource of the report. If you have to do this with code a valid approach would be the NeedDataSource of the subreport item itself:

private void subReport1_NeedDataSource(object sender, EventArgs e)
{
    Telerik.Reporting.Processing.SubReport subreport = sender as Telerik.Reporting.Processing.SubReport;
    subreport.InnerReport.DataSource = ods;  
}

If your scenario is different, please send us a runnable example with explanations what is it you're trying to achieve and we would advise you accordingly.

Kind regards,
Steve
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
Robot B9
Top achievements
Rank 2
answered on 31 May 2017, 08:28 PM

In the main I've set the subreport's data using the

Private Sub subRptHeader_NeedDataSource(sender As Object, e As EventArgs) Handles subRptHeader.NeedDataSource
      TryCast(sender, Telerik.Reporting.Processing.SubReport).InnerReport.DataSource = pb
End Sub

 

However, I cannot see, nor access, this  when stepping through the subreport's code. I want to cast the  back to the data object. But, when stepping into this, the  is empty. This worked before upgrading from Q42014 to the current report code, and the deprecation of the report object.

Inherits Telerik.Reporting.Report
   Protected Shared _phaseBalanceWidthFor100Pct As Telerik.Reporting.Drawing.Unit
   Protected _pb As PanelBoard = Nothing
   Protected ReadOnly Property pb() As PanelBoard
       Get
           If NotSet(_pb) Then
               _pb = CType(Me.Report.DataSource, PanelBoard)
           End If
           Return _pb
       End Get
   End Property

 

0
Stef
Telerik team
answered on 02 Jun 2017, 03:18 PM
Hello,

Below is a quote from my response to your inquiry in our support ticketing system:
You can set the DataSource of the processing report at run-time when the sub report requests its data (NeedDataSource event). In the sub report you will be able to access the data only through the processing report as the designed report's DataSource is not set (Me.DataSource) in order to have its NeedDataSource event fired.

You can create a user function accepting ReportItem.DataObject, where the function can be used in the sub report for getting its assigned data object.


If you need further help, please use one of both threads to share further details about the case.
Thank you for your understanding.

Regards,
Stef
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Robot B9
Top achievements
Rank 2
answered on 02 Jun 2017, 04:40 PM
I didn't need to use a function.
I simply caught the sender in the subReport, cast it to the appropriate processing object, and then used the object's .Report.DataSource to get the subreport's data.

Private Sub detail_ItemDataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles detail.ItemDataBinding
       Dim ds = DirectCast(sender, Telerik.Reporting.Processing.DetailSection)
       _pb = CType(ds.Report.DataSource, PanelBoard)
0
Stef
Telerik team
answered on 05 Jun 2017, 04:57 PM
Hello,

Please check the updated Understanding Events help article to determine if this usage of events will not bring further issues.

We can also suggest you to test the data binding approaches from How to bind Sub Report to Main Report's Data and Change Sub Report based on Main Report's Data.

Regards,
Stef
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Gersh
Top achievements
Rank 2
Answers by
Steve
Telerik team
Robot B9
Top achievements
Rank 2
Stef
Telerik team
Share this question
or