Skip to Content
author's profile photo Former Member
Former Member

subreport parameters

I can't get the sub-report to display data when printing from my C# code.

I have a main report with a sub-report. The main report has two parameters, one that is linked to the subreport. When I view the report in the editor or stand-alone Crystal Reprots the sub-report populates correctly, passing the linked parameter to the subreport.

When I print the report in code, nothing shows in the sub-report. I tried setting the parameter in the sub-report but recieved an error. I am using CR Developer 2008, Full version, 12.0.0.683, with Visual Studio 2008 (c# & WPF). I just purchased this version of CR and have not found any updates or hot fixes.

Here is the code:

CrystalDecisions.CrystalReports.Engine.ReportDocument report

= new CrystalDecisions.CrystalReports.Engine.ReportDocument();

report.Load("C:
Reports
UnitStatus.rpt");

report.Refresh();

report.SetDatabaseLogon("", "", "", ""); //(i removed these values)

report.SetParameterValue(0, true);

report.SetParameterValue(1,"B" );

report.PrintToPrinter(1, false, 1, 1)

Thanks for any help.

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 26, 2009 at 07:27 PM

    Hello,

    What are the errors you are getting?

    What type of database connection is used in the report? i.e. OLEDB to MS SQL Server

    When you load your report, you do not need the Refresh:

    You do not need to pass a value for a linked parameter - if the data is passed correctly to the main report there should be a valid value for the subreport parameter.

    report.Load("C:\\Reports\\UnitStatus.rpt");
    
    //Set the database logon
    report.SetDatabaseLogon("user","password","servername","database")

    This is a convenience method for logon to the database. It will only change the User ID and Password.

    If you need to change the Server Name and Database name from what is saved in the report, you need the full ConnectionProperties version of the logon code:

    //Setup the connection information structure to be used
       //to log onto the datasource for the report.
       ConnectionInfo crConnectionInfo = new ConnectionInfo();
       crConnectionInfo.ServerName = "sName";           //physical server name
       crConnectionInfo.DatabaseName = "dbName";   //database name (empty string for Oracle database)
       crConnectionInfo.UserID = "uid";
       crConnectionInfo.Password = "pwd";
    
       //Get the table information from the report
       crDatabase = crReportDocument.Database;
       crTables = crDatabase.Tables;
    
       //Loop through all tables in the report and apply the connection
       //information for each table.
       for (int i = 0; i < crTables.Count; i++)
       {
          crTable = crTables <i>;
          crTableLogOnInfo = crTable.LogOnInfo;
          crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
          crTable.ApplyLogOnInfo(crTableLogOnInfo);
          // Set the table location if the Owner.dbo.Tablename has changed from the report.
          crTable.Location = dbName + ".dbo." + crTable.Location;
       }

    Does the subreport use the same connection? If not you will need to logon to the subreport as well. for samples, look at the ReportDocument Object [tutorials|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b07a158a-b766-2b10-a79e-bfc6d19c6b99] and look at "RDObjMod_DBLogonSubrpt".

    Let me know if you have any questions.

    Elaine

    Edited by: Elaine Dove on Aug 26, 2009 12:29 PM

    Edited by: Elaine Dove on Aug 26, 2009 12:31 PM

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.