locked
Subreport fails to appear, at the Main Report RRS feed

  • Question

  • User-2033555810 posted

    Please help me.


    This is the first time, I tried to create a subreport in Crystal Report at a Web Page Microsoft Visual Studio 2010.

    I use two report files, consist of:

    crInvoice.rpt and crIMEIMobilePhones.rpt

    crInvoice.rpt is Main Report

    crIMEIMobilePhones.rpt is a file which will make the subreport at crInvoice.rpt

     

    below, the code I use to display Main Report and subreport. There might be a mistake. Please corrected.

    strSql = "select NoInvoice,IMEI, Namabarang,1 as Qty, hjual, diskon from tbtemp"
                                              
                        myDataAdapter = New MySqlDataAdapter(strSql, myConnection)
                        myDataAdapter.Fill(dsGrosir, "DTKwitansiGrosir")
                        If dsGrosir.Tables("DTKwitansiGrosir").Rows.Count > 0 Then
                            rpt = New crInvoice
                        
                            rpt.SetDataSource(dsGrosir)
                            
                            'below, a query that I use to display Sub Report
                            cmd.CommandText = "select Brand, IMEI from tbtemp"
                            cmd.CommandType = CommandType.Text
                            cmd.Connection = myConnection
                            If cmd.Connection.State = ConnectionState.Closed Then cmd.Connection.Open()
                            myDataAdapter.SelectCommand = cmd
                            myDataAdapter.Fill(ds1, "DTIMEI")
                            If ds1.Tables("DTIMEI").Rows.Count > 0 Then                 
                                rptSub = New crIMEIMobilePhones
                                rptSub.SetDataSource(ds1)
                            End If
                        
                            CrystalReportViewer1.ReportSource = rpt
                            CrystalReportViewer1.RefreshReport()
                        
                          
                        End If

    Thank you.

    Thursday, March 21, 2013 11:23 AM

Answers

  • User-578610739 posted

    Hi Frangky_koe,

    Is there link (common field to pass parameter value ) between  main report and subreport. please check solved answer with below link .

    http://scn.sap.com/thread/3214511

    generally for subreport we give datasource as

    //Get sub report and assign datatable1 to that report 
    foreach (ReportObject repOp in RptDoc.ReportDefinition.ReportObjects)
    {
    if (repOp.Kind == ReportObjectKind.SubreportObject)
    {
    string SubRepName = ((SubreportObject)repOp).SubreportName;
    ReportDocument subRepDoc = RptDoc.Subreports[SubRepName];
    subRepDoc.SetDataSource(dt1);
    }
    }

    Also check you coding with below link .

    http://www.dotnetspider.com/resources/43691-How-create-sub-reports-crystal-report.aspx ( directly go to Default2 Page Server side  section)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 22, 2013 1:40 AM

All replies

  • User-578610739 posted

    Hi Frangky_koe,

    Is there link (common field to pass parameter value ) between  main report and subreport. please check solved answer with below link .

    http://scn.sap.com/thread/3214511

    generally for subreport we give datasource as

    //Get sub report and assign datatable1 to that report 
    foreach (ReportObject repOp in RptDoc.ReportDefinition.ReportObjects)
    {
    if (repOp.Kind == ReportObjectKind.SubreportObject)
    {
    string SubRepName = ((SubreportObject)repOp).SubreportName;
    ReportDocument subRepDoc = RptDoc.Subreports[SubRepName];
    subRepDoc.SetDataSource(dt1);
    }
    }

    Also check you coding with below link .

    http://www.dotnetspider.com/resources/43691-How-create-sub-reports-crystal-report.aspx ( directly go to Default2 Page Server side  section)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 22, 2013 1:40 AM
  • User1243880387 posted

    The better way could be:

    rptSub = New crIMEIMobilePhones
    rptSub.SetDataSource(ds1)
    
    use: 
    
     rpt.Subreports[0].SetDataSource(ds1);
    
    Also You can give the name as when I was having more than one subreport the above method was failing, so I gave the name in string in the same like:
    
     rpt.Subreports["crIMEIMobilePhones"].SetDataSource(ds1);



    Friday, March 22, 2013 1:51 AM