Parameters not being passed into rdlc reports - c#

I am trying to display rdlc reports in c# windows aplication.I am passing parameters to the report by this code-named
localReport.SetParameters(new ReportParameter[] { new ReportParameter("JobC", m) });
I have defined this parameter in the report also. But the parameter is not being passed into the report and the database table is not getting filtered. The first record, though, is being displayed., how to solve this error?

1.Go to the rdlc Design view
2.on the report data view (On the left) select parameters
3.Right click Add
4.set the name (best you Check Allow blank and allow null value)click OK
5.add the textfiled value OR select one from your tablix,right click and select Expression
6.set the expression e.g
=Parameters!title.Value
7.In your form that contains your report view add the following lines for a single parameter
ReportParameter rp = new ReportParameter("title", title); this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp });
});
reportViewer1.RefreshReport();
8.for multiple parameters
ReportParameter rp = new ReportParameter("title", title);
ReportParameter rps = new ReportParameter("expense", totalExpense.ToString());
this.reportViewer1.LocalReport.SetParameters(new R`enter code here`eportParameter[] { rp });
this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rps });
reportViewer1.RefreshReport();

Related

How to pass multiple parameters to Crystal Reports using C#?

I used this code to pass a parameter to Crystal Reports, but I can't pass multiple parameters. How can I change this code to pass multiple parameters from C# to Crystal Reports?
this.Cursor = Cursors.WaitCursor;
RPT.RPT_Sale_by_day report = new RPT.RPT_Sale_by_day();
RPT.Form_RPT frm = new RPT.Form_RPT();
report.SetParameterValue("#date1", dt_num1.Value);
frm.crystalReportViewer1.ReportSource = report;
frm.ShowDialog();
this.Cursor = Cursors.Default;
//Initiating created Crystal Report
ParameterValues Params =new ParameterValues(); // Creating collection of parameters
ParameterDiscreteValue Par_Ref =new ParameterDiscreteValue(); // Discrete parameter that comes from SP and shows on Crystal Report
String PARAMETER1_VALUE ="123";
String PARAMETER2_VALUE = "ABC";
Params.Clear(); // Cleaning data collection
Par_Ref.Value = PARAMETER1_VALUE; // Assigning discrete value to our variable
Params.Add(Par_Ref); //Adding discrete parameter to parameter collection
report.DataDefinition.ParameterFields["PARAMETER1_NAME"].ApplyCurrentValues(Params); //Applying values from our collection to Crystal Report parameters
Params.Clear();
Par_Ref.Value = PARAMETER2_VALUE;
Params.Add(Par_Ref);
report.DataDefinition.ParameterFields["PARAMETER2_NAME"].ApplyCurrentValues(Params);

Set Parameters RDLC Report C#

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.

How to pass a parameter to an SSRS report query?

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.

How to Bind rdlc report using business object?

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

Switching DataSources in ReportViewer in WinForms

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.

Categories