on 02-05-2024 12:56 PM
Hello,
I have two subreport included in a main report. Each subreport contain a datasource.
When I try to setdatasource in subreport from asp.net c#, it return an error which say Missing parameter values.
My subreports are on demand and my main report doesn't have any datasource
Thanks in adance
Your subreports are coming back blank because setting the datasource at the subreport level doesn't work. In both the main report and any subreports, you have to walk through the tables and set the datasource on the tables themselves.
The code for setting the login for the data in the subreports should look something like this:
private void ConfigureCrystalReports()
{
northwindCustomersReport = new ReportDocument();
string reportPath = Application.StartupPath + "\\" + "NorthwindCustomers.rpt";
northwindCustomersReport.Load(reportPath);
//Build the ConnectionInfo used for assigning credentials for the data
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "localhost";
connectionInfo.DatabaseName = "Northwind";
connectionInfo.IntegratedSecurity = true;
crystalReportViewer.ReportSource = northwindCustomersReport;
//Set credentials for the main report
SetDBLogonForReport(connectionInfo, northwindCustomersReport);
//Set credentials for the subreports
SetDBLogonForSubreports(connectionInfo, northwindCustomersReport);
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo,
ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
private void SetDBLogonForSubreports(ConnectionInfo connectionInfo,
ReportDocument reportDocument)
{
Sections sections = reportDocument.ReportDefinition.Sections;
foreach (Section section in sections)
{
ReportObjects reportObjects = section.ReportObjects;
foreach (ReportObject reportObject in reportObjects)
{
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject subreportObject = (SubreportObject)reportObject;
ReportDocument subReportDocument =
subreportObject.OpenSubreport(subreportObject.SubreportName);
SetDBLogonForReport(connectionInfo, subReportDocument);
}
}
}
This code was taken from the sample code that can be downloaded from the "SAP Crystal Reports .NET SDK Tutorial Sample Code" link on the Crystal for VS Help page.
-Dell
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Now I've moved on a bit.
This is how I load my mainReport which contains two subreports
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(Server.MapPath("~/Documents/DocumentGlobal.rpt"));
After that, I set the datasource for each subreport like this :
DataTable dt = CreateAttPres();
reportDocument.Subreports[0].SetDataSource(dt);
DataTable dt = CreateAttRemb);
reportDocument.Subreports[1].SetDataSource(dt);
But when I try to generate them, they are empty
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have set the reports data source to a dataset, doesn't appear the data set has any data in it.
Use the same code as what Dell showed you and your report should start working.
For more info and sample try my Parameter test app, single step through it to see what is happening:
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.