on 08-25-2009 3:01 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
61 | |
9 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.