0
votes

I use 2 sub reports in my crystal report. Both these reports are not have any link or relation to each other. but have relation with main report with evidence.

enter image description here

my code :

    dim mReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    dim querymain, query1, query2 As String

    mReport = New CrystalReport1
    querymain = "SELECT * from tblmain where evidence = '" & EvD & "'"
    Call DataSourceConnection_Report() 'my setconnection and setlogon
    mReport.Database.Tables(0).SetDataSource(ExecuteSQLQuery(querymain))

    query1 = "SELECT * FROM tbl1 WHERE EVIDENCE = '" & EvD & "'"
    mReport.Subreports("sub2").SetDataSource(ExecuteSQLQuery(query1))

    query2 = "SELECT * FROM tbl2 WHERE EVIDENCE = '" & EvD & "'"
    mReport.Subreports("sub3").SetDataSource(ExecuteSQLQuery(query2))
    CrystalReportViewer1.Refresh()
    CrystalReportViewer1.ReportSource = mReport

but it will only show my main report data and leave my sub report empty.

how to fill my sub report ?

1

1 Answers

1
votes

You should instantiate your sub-reports like:

mReport As New CrystalReport1
querymain = "SELECT * from tblmain where evidence = '" & EvD & "'"
Call DataSourceConnection_Report()
mReport.Database.Tables(0).SetDataSource(ExecuteSQLQuery(querymain))

Dim sub2 As CrystalDecisions.CrystalReports.Engine.ReportDocument
sub2 = mReport.OpenSubreport("sub2")
sub2.SetDataSource(ExecuteSQLQuery(query1))

Dim sub3 As CrystalDecisions.CrystalReports.Engine.ReportDocument
sub3 = mReport.OpenSubreport("sub3")
sub3.SetDataSource(ExecuteSQLQuery(query2))