I have created a report in my C# ASP.net web application, to generate a cover page of a proposal. I am attempting to pass the proposal ID to the report. My dataset is set up to accept the proposal ID as a query parameter, and I have the GetByProposalID and FillByProposalID methods defined.
The problem is that when the report runs, the report viewer does not contain data. Either the problem is in my code, or in my report / report viewer configuration.
Here's my method:
/// <summary>
/// Generate the cover page report as a PDF file from a given proposal
/// </summary>
/// <param name="ProposalID">Proposal ID from the database of the proposal</param>
public void GenerateCoverPage( int ProposalID )
{
ReportViewer viewer = new ReportViewer();
viewer.Reset();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = "ReportCoverPage.rdlc"; //sets the report from the project RDLC file
//Connect the dataset to the report
ds_ReportCoverPage ds = new ds_ReportCoverPage();
ds_ReportCoverPage.dt_ReportCoverPageDataTable table = new ds_ReportCoverPage.dt_ReportCoverPageDataTable();
ds_ReportCoverPageTableAdapters.dt_ReportCoverPageTableAdapter ta = new ds_ReportCoverPageTableAdapters.dt_ReportCoverPageTableAdapter();
ta.FillByProposalID(table, ProposalID); //This SHOULD fill the adapter with the data from the selected proposal
ReportDataSource source = new ReportDataSource("ds_Report_ReportCoverPage", ds.Tables[0]); //Name must match the data source name within the report
viewer.LocalReport.DataSources.Add(source);
//Run-time exception that there is no report parameter "#Proposal"
//ReportParameter parm = new ReportParameter("#Proposal", ProposalID.ToString()); //Placeholder in report query
//viewer.LocalReport.SetParameters(parm);
viewer.LocalReport.Refresh();
string filepath = "C:\\Temp\\foo.pdf";
SavePDF(viewer, filepath);
}
As you can see, I tried to pass the parameter as a ReportParameter, but the parameter is in the query and not the report so it was rejected.
(I've gotten this far thanks to looking up other questions on SO.)
You will need a parameter in the report and then you can map that parameter to the parameter in the query in the data set.
Related
In my rdlc report I create parameter test. In form I write below code to set parameter:
//Set Parameters
ReportParameter[] p = new ReportParameter[1];
p[0] = new ReportParameter("Test", "Testing");
currentBilling_rv.LocalReport.SetParameters(p);
// Provide datasource to report Current_Total_Billing.rdlc
ReportDataSource rds = new ReportDataSource("CurrentTotalBilling", dataset.Tables[2]);
currentTotalBilling_rv.LocalReport.DataSources.Clear();
currentTotalBilling_rv.LocalReport.DisplayName = "Current Total Billing";
currentTotalBilling_rv.LocalReport.ReportPath = ".\\Current_Total_Billing.rdlc";
currentTotalBilling_rv.LocalReport.DataSources.Add(rds);
currentTotalBilling_rv.RefreshReport();
When I run the program I have exception
An unhandled exception of type
'Microsoft.Reporting.WinForms.MissingReportSourceException' occurred
in Microsoft.ReportViewer.WinForms.dll
Additional information: The source of the report definition has not
been specified
Please help.
In your code you are setting a parameter for a ReportViewer named currentBilling_rv not for currentTotalBilling_rv which is used in the next lines of code.
If currentBilling_rv name is correct verify that currentBilling_rv.LocalReport.ReportPath is compiled.
i have business object called "TeamMaster",
in which i define three properties,Id,Name & Flg.
in my .rdlc report i apply TeamMaster object as a data source,
now i write the following code in page load event of form in which i add report viewer control and i define my report as a local report.
using (RDLC_DEMO_DBEntities objdatabase = new RDLC_DEMO_DBEntities())
{
lstTeamMstr = objdatabase.TeamMasters.ToList();
}
this.TeamMasterBindingSource.DataSource = lstTeamMstr;
this.reportViewer1.RefreshReport();
when i check this code using debugging i get 6 records in TeamBindingSource,
but in windows report only displays six blank rows,
what is the problem?
Follow this code : >>
string path = HttpContext.Current.Server.MapPath(Your Report path);
ReportViewer1.Reset(); //important
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
// Add sub report even handler if you need
***ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(MySubreportProcessingEventHandler);***
LocalReport objReport = ReportViewer1.LocalReport;
objReport.ReportPath = path;
// Add Parameter If you need
List<ReportParameter> parameters = new List<ReportParameter>();
parameters.Add(new ReportParameter("Name", Value));
ReportViewer1.LocalReport.SetParameters(parameters);
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowPromptAreaButton = false;
ReportViewer1.LocalReport.Refresh();
//Add Datasourdce
ReportDataSource reportDataSource = new ReportDataSource();
reportDataSource.Name = "Datasource Name Used due to report design";
reportDataSource.Value = DataSourceValue(Your object data-source);
objReport.DataSources.Add(reportDataSource);
objReport.Refresh();
Here Subreport Even handler code
private void MySubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
{
//You can get parameter from main report
int paramname = int.Parse(e.Parameters[0].Values[0].ToString());
//You can also add parameter in sub report if you need like main report
//Now add sub report data source
e.DataSources.Add(new ReportDataSource("DataSource Name",DataSourceValue)));
}
If you need to create Drillthrough report than follow this link Click here for Drillthrough report
Working with .RDLC 2005 in VS 2008 this technique worked very well, now in .RDLC 2008 as implemented in VS 2010 I get a blank (or no?) report.
I have made a couple of changes to accommodate .RDLC 2008 and at this time I am getting no exceptions. The present (not desired) output looks like:
I have a custom ReportController class that has a public method to ShowReport (also one to manage the exporting of reports, but that is not (yet) in play.)
From the asp.net page I invoke the controller in the property set (of Type DataSet, invoked by the page controller) like: (ReportController implements IDisposable)
try
{
using (var reportController = new ReportController(true))
{
_ReportViewer = reportController.ShowReport("DemonstrationList", value, phReportHolder);
if (_ReportViewer != null)
{
_ReportViewer.ShowRefreshButton = false;
_ReportViewer.ShowPrintButton = false;
_ReportViewer.Width = Unit.Pixel(700);// Unit.Percentage(99);
_ReportViewer.Height = Unit.Pixel(700);// Unit.Percentage(90);
}
}
lblRecordCount.InnerText = value.Tables[0].Rows.Count.ToString();
}
catch (Exception ex)
{
phReportHolder.InnerHtml = string.Format("There was an error attempting to process this report <br/><br/><div style='color:White;'>{0}</div>", ex.Message);
}
and the ShowReport method is:
public ReportViewer ShowReport(string ReportName, DataSet ds, HtmlContainerControl ReportContainer)
{
ReportContainer.Controls.Clear();
ReportViewer reportViewer = BuildReport(ReportName, ds);
ReportContainer.Controls.Add(reportViewer);
return reportViewer;
}
This allows me to tell the controller to put any 'valid' report into any htmlcontainercontrol using any provided dataset.
BuildReport takes the data and the report name and builds the report as:
private ReportViewer BuildReport(string ReportName, DataSet ds)
{
try
{
_activeDS = ds;
string ReportFileName = ResolveRDLCName(ReportName);
// ResolveRDLCName is used along with path strings
// initialized from configuration settings in the
// constructor to make this portable.
var viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = ReportFileName;
viewer.LocalReport.DisplayName = ReportName;
viewer.LocalReport.EnableHyperlinks = true;
AssignReportData(ds, viewer.LocalReport);
return viewer;
}
//...Exception handlers below are not invoked at this time
And 'AssignReportData' attaches the data to the report.
private static void AssignReportData(DataSet ds, LocalReport Report)
{
var listOfDatasources = Report.GetDataSourceNames();
foreach (string dsn in listOfDatasources)
{
ReportDataSource rds = new ReportDataSource(dsn,ds.Tables[dsn]);
Report.DataSources.Add(rds);
}
}
Development techniques ensure that dataTable/dataSource names stay in agreement (and if they were not I would get a specific exception, which I do not.)
I was having a similar problem which this blog post answered. Short answer is I needed to install the report viewer redistributable, and add the handler.
It seems like the report content gets rendered but is simply not visible.
Try to look at the generated HTML (DOM) with
Chrome: right-click on the report area, "Inspect Element" to explore the DOM
Internet Explorer: install the IE Developer Toolbar to explore the DOM
Maybe some CSS that has worked in the past now hides your report area.
I have created a dataset and using it in my crystal report. Issue is that at design time i am able to display the data but when I execute it using ASP.Net page its showing a blank page. Below is my code that i am using to display the report programatically:
/// <summary>
/// Displays batch report
/// </summary>
/// <param name="agreementId"></param>
private void ShowStatements(string agreementId)
{
var crvStatements = new CrystalReportViewer();
var reportDocument = new ReportDocument();
reportDocument.Load(Server.MapPath("Statements.rpt"));
crvStatements.ReportSource = reportDocument;
var dt1 = new dsStatements.usp_GetBillDetailsByAgreementIdDataTable();
var dt2 = new dsStatements.usp_GetTransactionTypesByAgreementIdForBillDataTable();
var adapter1 = new usp_GetBillDetailsByAgreementIdTableAdapter();
var adapter2 = new usp_GetTransactionTypesByAgreementIdForBillTableAdapter();
adapter1.Fill(dt1, agreementId);
adapter2.Fill(dt2, agreementId);
//var statements = new dsStatements();
//statements.Tables.Add(dt1);
//statements.Tables.Add(dt2);
// reportDocument.SetDataSource(dsStatements);
crvStatements.RefreshReport();
}
Please note that i haven't used any control on the page. I am adding report viewer , report source and dataset programatically. Please help me out. I need it ASAP. I am using VS2010 with CR 2010
Can you provide the reason why you are creating the Crystal Report Viewer at runtime and not simply creating the control on the page? Some people do this so that they can export without displaying, but I don't see any code for that.
I haven't tested this, but I believe the below would work if you had a viewer control on your page.
private void ShowStatements(string agreementId)
{
//var crvStatements = new CrystalReportViewer(); //created on the page
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(Server.MapPath("Statements.rpt"));
crvStatements.ReportSource = reportDocument;
System.Data.DataTable dt1 = new dsStatements.usp_GetBillDetailsByAgreementIdDataTable();
System.Data.DataTable dt2 = new dsStatements.usp_GetTransactionTypesByAgreementIdForBillDataTable();
System.Data.DataSet statements = new System.Data.DataSet();
statements.Tables.Add(dt1);
statements.Tables.Add(dt2);
reportDocument.SetDataSource(dsStatements);
crvStatements.DataBind();
}
I'm assuming that the report is set up with these tables linked in the report, and you may have to give the datatables a name so that Crystal knows how to map each datatable to the corresponding table within the report. If possible you may try to limit the report to accepting a single table until you have the loading logic worked out.
If each of these datatables represent the data for a subreport then you'll have to iterate through those reports and set the datasources manually.
I hope this helps, but I answered this off the top of my head so there are probably things I've missed. If it doesn't work you just provide a comment and we can probably work through any issues.
The RefreshReport(); makes the Report appearing Empty. try it before loading the Datasets.
I have created a winform for the users to view view the many reports I am creating for them. I have a drop down list with the report name which triggers the appropriate fields to display the parameters. Once those are filled, they press Submit and the report appears. This works the first time they hit the screen. They can change the parameters and the ReportViewer works fine. Change to a different report, and the I get the following ReportViewer error:
An error occurred during local report processing.
An error has occurred during the report processing.
A data source instance has not been supplied for the data source "CgTempData_BusMaintenance".
As far as the process I use:
I set reportName (string) the physical RDLC name.
I set the dataSource (string) as the DataSource Name
I fill a generic DataTable with the data for the report to run from.
Make the ReportViewer visible
Set the LocalReport.ReportPath = "Reports\\" = reportName;
Clear the LocalReport.DataSources.Clear()
Add the new LocalReport.DataSources.Add(new ReportDataSource(dataSource, dt));
RefreshReport() on the ReportViewer.
Here is the portion of the code that setups up and displays the ReportViewer:
/// <summary>
/// Builds the report.
/// </summary>
private void BuildReport()
{
DataTable dt = null;
ReportingCG rcg = new ReportingCG();
if (reportName == "GasUsedReport.rdlc")
{
dataSource = "CgTempData_FuelLog";
CgTempData.FuelLogDataTable DtFuelLog = rcg.BuildFuelUsedTable(fromDate, toDate);
dt = DtFuelLog;
}
else if (reportName == "InventoryCost.rdlc")
{
CgTempData.InventoryUsedDataTable DtInventory;
dataSource = "CgTempData_InventoryUsed";
DtInventory = rcg.BuildInventoryUsedTable(fromDate, toDate);
dt = DtInventory;
}
else if (reportName == "VehicleMasterList.rdlc")
{
dataSource = "CgTempData_VehicleMaster";
CgTempData.VehicleMasterDataTable DtVehicleMaster = rcg.BuildVehicleMasterTable();
dt = DtVehicleMaster;
}
else if (reportName == "BusCosts.rdlc")
{
dataSource = "CgTempData_BusMaintenance";
dt = rcg.BuildBusCostsTable(fromDate, toDate);
}
// Setup the DataSource
this.reportViewer1.Visible = true;
this.reportViewer1.LocalReport.ReportPath = "Reports\\" + reportName;
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource(dataSource, dt));
this.reportViewer1.RefreshReport();
}
Any ideas how to remove all of the old remaining data? Do I dispose the object and recreate it?
I figured it out. I needed to add: reportViewer1.Reset(); to the beginning of the method.