public WebForms.ReportViewer ReportViewer() { FileInfo reportFullPath = this.ReportFile; //check to make sure the file ACTUALLY exists, before we start working on it if (reportFullPath != null) { //map the reporting engine to the .rdl/.rdlc file LoadReportDefinitionFile(CurrentReportViewer.LocalReport, reportFullPath); // 1. Clear Report Data CurrentReportViewer.LocalReport.DataSources.Clear(); // 2. Load new data // Look-up the DB query in the "DataSets" element of the report file (.rdl/.rdlc which contains XML) RDL.Report reportDef = this.ReportDefinition; //Load any other report parameters (which are not part of the DB query). //If any of the parameters are required, make sure they were provided, or show an error message. Note: SSRS cannot render the report if required parameters are missing CheckReportParameters(CurrentReportViewer.LocalReport); if (!ErrorMessages.Any()) { // Run each query (usually, there is only one) and attach each to the report foreach (RDL.DataSet ds in reportDef.GetDataSetsInReportSections()) { WebForms.ReportDataSource rds = GetReportDataSource(reportDef, ds); CurrentReportViewer.LocalReport.DataSources.Add(rds); } } CurrentReportViewer.LocalReport.Refresh(); } return(CurrentReportViewer); }
private WebForms.ReportDataSource GetReportDataSource(RDL.Report reportDef, RDL.DataSet ds) { //copy the parameters from the QueryString into the ReportParameters definitions (objects) var parameters = CurrentReportViewer.LocalReport.GetParameters(); ds.AssignParameters(parameters); var dataSource = reportDef.DataSources.Find(d => d.Name == ds.Query.DataSourceName); //run the query to get real data for the report System.Data.DataTable tbl = ds.GetDataTable(dataSource.ConnectionProperties.ConnectString); //attach the data/table to the Report's dataset(s), by name //This refers to the dataset name in the RDLC file return(new WebForms.ReportDataSource { Name = ds.Name, Value = tbl }); }
private DataTable GetData(string parameterName, string dataSourceName) { FileInfo reportFullPath = this.ReportFile; //check to make sure the file ACTUALLY exists, before we start working on it if (reportFullPath == null) { return(null); } var errorMessages = new List <ErrorMessage>(); //map the reporting engine to the .rdl/.rdlc file LoadReportDefinitionFile(CurrentReportViewer.LocalReport, reportFullPath); // Look-up the DB query in the "DataSets" element of the report file (.rdl/.rdlc which contains XML) RDL.Report reportDef = this.ReportDefinition; CheckReportParameters(CurrentReportViewer.LocalReport); var parameter = reportDef.ReportParameters.FirstOrDefault(p => p.Name.Equals(parameterName)); if (parameter == null) { ReportSingleErroMessage($"The parameter {parameterName } was not found in report {ReportName}"); return(null); } // Run each query (usually, there is only one) and attach each to the report var validValue = parameter.ValidValues.FirstOrDefault(v => v.DataSetName.Equals(dataSourceName)); if (validValue == null) { ReportSingleErroMessage($"The parameter {parameterName } has no valid DataSetName ({dataSourceName}) for report {ReportName}"); return(null); } RDL.DataSet ds = parameter.ValidValues.FirstOrDefault().DataSet; WebForms.ReportDataSource rds = GetReportDataSource(reportDef, ds); return((DataTable)rds.Value); }