How to display subreport data using Telerik reporting version10.1.16.504

4 posts, 0 answers
  1. Venessa
    Venessa avatar
    2 posts
    Member since:
    May 2015

    Posted 11 May Link to this post

    Hi,

            I am new in using Telerik reporting and considering moving from Crystal Report. I need help on display subreport data in WPF VS 2015. The application able to display the master report data but it doesn't show subreport data after added code for subreport. Below is my sample code.

     

          private void frmMainWindowB_Loaded(object sender, RoutedEventArgs e)
            {
                //Get data
                var objectDataSourceSub = new Telerik.Reporting.ObjectDataSource();
                objectDataSourceSub.DataSource = GetSubData1(); // GetData returns a DataTable

                var objectDataSourceMain = new Telerik.Reporting.ObjectDataSource();
                objectDataSourceMain.DataSource = GetMainData(); // GetData returns a DataTable
                //


                var mainreport = new MyReportLib.SampleBMainRpt();   

                var Bsubrpt1 = new MyReportLib.SampleBSubReport1();
                
                Telerik.Reporting.SubReport subreport1 = mainreport.Items.Find("subReport1", true).FirstOrDefault() as Telerik.Reporting.SubReport;
                
                var reportSource = new Telerik.Reporting.InstanceReportSource();
                reportSource.ReportDocument = mainreport;
                mainreport.DataSource = objectDataSourceMain;

                var SUBreportSource = new Telerik.Reporting.InstanceReportSource();
                Bsubrpt1.DataSource = objectDataSourceSub;
                SUBreportSource.ReportDocument = Bsubrpt1;

                subreport1.ReportSource = Bsubrpt1;
                
                reportViewerB.ReportSource = reportSource;
                reportViewerB.RefreshReport();

            }

     

  2. Katia
    Admin
    Katia avatar
    309 posts

    Posted 14 May Link to this post

    Hello Venessa,

    Note, that there is no need to create a ReportSource instance for the subreport as well. Add Subreport item to master report's definition and then set report source of the viewer to master report.
    Subreport can have its own data source and reuse the parent's (master report) data source - Binding to data from the parent data item.

    Check the attached project demonstrating the recommended approach to display master-detail report in WPF application. You might need to run Upgrade Wizard to downgrade Telerik Reporting assembly references to the version installed on your machine.

    Details on how to configure WPF Report Viewer are available in WPF Application Manual Setup help article.


    Regards,
    Katia
    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
  3. DevCraft banner
  4. Venessa
    Venessa avatar
    2 posts
    Member since:
    May 2015

    Posted 03 Jun in reply to Katia Link to this post

    Hello Katia,

                    Thanks for the sample program, I manage to display report using hard code statement. I am looking into to how to generate report  using the same Master & Detail but datasource is referring to dataset and statement is define during loading process.The Master report content is able to display, however it is not able to display subreport content. I am using below code to generate data in runtime. Attach is the properties for both Master and Details report. I hope you can direct me which area/code I have miss out.

       private void displayReportData()
            {
                using (SqlConnection connection = new SqlConnection("Data Source = (local); Initial Catalog = AdventureWorks; Integrated Security = True"))
                {
                    string selectCommandText = "SELECT SalesOrderID, SalesOrderNumber, PurchaseOrderNumber FROM[AdventureWorks].[Sales].[SalesOrderHeader] WHERE SalesOrderID < 43667";

                    SqlDataAdapter dsAdapter = new SqlDataAdapter(selectCommandText, connection);
                    MyReportLib.AdventureWorks.DataSet.MainDataSet  ds = new MyReportLib.AdventureWorks.DataSet.MainDataSet() ;
                    dsAdapter.Fill(ds, "SalesOrderHeader");

                    var salesreport = new MyReportLib.AdventureWorks.Report.SalesOrderHeaderRpt();
                    salesreport.DataSource = ds.SalesOrderHeader;
               
                    string detailSQL = "select A.SalesOrderID , A.ProductID , B.NAME , A.OrderQty , A.UnitPrice , A.LineTotal FROM [AdventureWorks].[Sales].SalesOrderDetail A, " +
                                       "[AdventureWorks].[Production].[Product] B WHERE A.ProductID  = B.ProductID AND A.SalesOrderID < 43667";

                    SqlDataAdapter DTAdapter = new SqlDataAdapter(detailSQL , connection);
                    MyReportLib.AdventureWorks.DataSet.SubDataSet dt = new MyReportLib.AdventureWorks.DataSet.SubDataSet();
                    DTAdapter.Fill(dt, "SalesOrderDetail");

                    var detailreport = new MyReportLib.AdventureWorks.Report.SalesOrderDetailsRpt();
                    InstanceReportSource detailSource = new InstanceReportSource() { ReportDocument = detailreport };
                    detailreport.DataSource = ds.SalesOrderHeader;
                    
                    rptViewer.ReportSource = new InstanceReportSource() { ReportDocument = salesreport };
                }
            }

     

     

     

  5. Katia
    Admin
    Katia avatar
    309 posts

    Posted 07 Jun Link to this post

    Hello Venessa,

    In the provided code, you set the DataSource of a newly created SalesOrderDetailsRpt. However, this will be applied after the report is rendered and in report's default constructor SalesOrderDetailsRpt subreport will be rendered without any data (as it is set in the Designer).

    The recommended approach for connecting the report with data from SQL database is via SqlDataSource component. You can use dedicated SqlDataSource Wizard that will guide you through the steps of connecting to data.
    You can optionally configure data source parameters that can be updated according to report parameters - Using Parameters with the SqlDataSource component.

    After the data source component is configured, set it as DataSource property of SalesOrderDetailsRpt in the Designer.
    Detail reports can also reuse the parent's (master report) data source - Binding to data from the parent data item.

    You can check Invoice report demonstrating how to create master-detail relationship located in installation directories.


    Regards,
    Katia
    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
Back to Top