• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 591
  • Last Modified:

Pass Values to TextObjects in a Subreport?

I have a report with a subreport in it and that subreport needs to contain information that isn't pulled from the stored procedure that it is linked with to obtain other data. My report runs the subreport many times for each record.

I am needing to pass values to text objects in these individual subreports that is information that is obtained in the code. My code works fine when this subreport is ran on it's own but I can't get the values sent to the subreports. Here is a simple example of some of my code:

 
using (PrintBills reportPrintBills = new PrintBills())
{
    using (CrystalReportBill reportBill = new CrystalReportBill())
    {
        CrystalDecisions.CrystalReports.Engine.TextObject lblBalanceDue = ((CrystalDecisions.CrystalReports.Engine.TextObject)reportBill.Summary.ReportObjects["lblBalanceDue"]);
        CrystalDecisions.CrystalReports.Engine.TextObject lblName = ((CrystalDecisions.CrystalReports.Engine.TextObject)reportBill.Summary.ReportObjects["lblName"]);
 
        DataSet ds = new DataSet();
        GetBills(ref ds, "Bills", date);
        DataView dvID = new DataView(ds.Tables["Bills"]);
        num = 0;
 
        foreach (DataRowView rowID in dvID)
        {
            GetBioInfo(ref ds, "BioData", id);
            DataRow row = ds.Tables["BioData"].Rows[num];
            lblName.Text = row["Stu_Name"].ToString();
            lblBalanceDue.Text = String.Format("{0:C}", row["Amount_Due"]);
            num++;
        }
 
    }
    
    reportPrintBills.SetParameterValue("@tblMonth", date);
    reportPrintBills.SetParameterValue("@begdate", strBegdate);
    reportPrintBills.SetParameterValue("@enddate", strEnddate);
 
    //Export to PDF code here
}

Open in new window


reportBill does not display the values obviously. Somehow I need to set that reportBill is a subreport of reportPrintBills in the code so that each record will recognize the TextObject values that I am sending to them. I need the values to be different for each subreport.

I have tried the following but this didn't work:

 
using (PrintBills reportPrintBills = new PrintBills())
{
    ReportDocument reportBill = new ReportDocument();
    reportBill = reportPrintBills.OpenSubreport("subReportBill");
    using (reportBill)
    {
        CrystalDecisions.CrystalReports.Engine.TextObject lblName = ((CrystalDecisions.CrystalReports.Engine.TextObject)reportBill.Summary.ReportObjects["lblName"]);

Open in new window


I get the errors for each of the TextObjects I'm trying to define:

'CrystalDecisions.CrystalReports.Engine.ReportDocument' does not contain a definition for 'Summary'

Am I on the right track here?


Another solution I've tried is adding parameter fields to reportBill and reportPrintBills and linking them up and then passing values like so:

foreach (DataRowView rowCWID in dvCWID)
{
    GetBioInfo(ref ds, "BioData", id);
    DataRow row = ds.Tables["BioData"].Rows[num];
    name = row["Stu_Name"].ToString();
    amtDue = String.Format("{0:C}", row["Amount_Due"]);
    reportPrintBills.SetParameterValue("@strName", name);
    reportPrintBills.SetParameterValue("@strAmtDue", amtDue);
    num++;
}

Open in new window


But the value stays the same in all of the subreports rather than changing with each pass through due to the fact that it only ends up setting the value of the parameter to the last name that was passed before exporting the pdf.
0
FIM2003
Asked:
FIM2003
  • 5
  • 4
1 Solution
 
mlmccCommented:
Your code doesnt run the report in the  sense you are thinking.
You cannot pass information in to each instance of the subreport and have that information be different.

WHen you pass information from code to the report it is passed before the report is run and then used in the report.  Once the report starts running there is little interaction with the code.

In order to do what you want you will have to run the report for each row in turn.

mlmcc


0
 
FIM2003Author Commented:
I would need to run the report for each row or the subreport for each row?

All the report does is use a stored procedure to obtain all of the ids that need subreports created so in the end, I would need all of these to be in a single pdf file.

If it's not possible to send values to the TextObjects of each individual subreport, would I be able to get rid of the report (running what is now the subreport as the main report) and then run it many times but save all of the results in a single pdf?
0
 
mlmccCommented:
You could do that.   There are third party tools that can merge PDFs into a single PDF.

ANy particular reason you can't have the other data in the report?

You could build a report based on that dataset and link the subreport to it.

mlmcc
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
FIM2003Author Commented:
I'd rather not have to go the route of creating thousands of pdfs and joining them together if I can keep from it.

Well the data in the subreport uses a different stored procedure to pull it. I'm not sure that I could use two stored procedures within a report? Maybe I can but in the past when I have tried it, I'd get warnings about more than one datasource being used in the report.
0
 
mlmccCommented:
Unless you can join them they shouldn't be in the same report.  However you could use one as the source for the main report and the other as the source for the subreport.

mlmcc
0
 
FIM2003Author Commented:
Yeah, that's what I'm currently doing. I just need to fill those other voids in the subreport that neither stored procedure can fill. But if this isn't possible then we may just have to look into computing some things in the stored procedure.
0
 
mlmccCommented:
Since you are using a stored procedure, you can't use a SQL Expression.

Can you add another subreport to get the missing data?

mlmcc
0
 
FIM2003Author Commented:
The way we're going to get around this is to great a new standard procedure and add a few things to the existing ones so that all of this doesn't have to be obtained through the code.
0
 
FIM2003Author Commented:
Didn't figure out a solution that I would have liked but we're working around it.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now