I have a C# application that uses a reportViewer. I want to add 3 reports in a single reportViewer. Here is the code for a single report:
ReportDataSource rds = new ReportDataSource();
this.reportViewer1.LocalReport.DataSources.Clear();
if (comboBoxReports.SelectedIndex == 0)
{
reportViewer1.Reset();
reportViewer1.LocalReport.ReportPath = "D:\\AMOS\\WindowsFormsApplication1\\WindowsFormsApplication1\\Report2.rdlc";
rds.Name = "First_Year_IT_AttendanceBindingSource";
rds.Value = this.First_Year_IT_AttendanceBindingSource;
reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.RefreshReport();
}
However when I run my application, I get the following error
A data source instance has not been supplied for the data source 'DataSet1'
What can be the possible mistake?
Open rdlc file as text
Replace DataSet1 with First_Year_IT_AttendanceBindingSource
Check that the columns (fields) in rdlc is 'equal' to columns in your data source
Related
I am facing a problem while working with Reports in WPF... I have created an event
private void Window_Loaded(object sender, RoutedEventArgs e) {
try {
admissionReportViewer.Owner = Window.GetWindow(this);
if (_admissionNumber != 0) {
rd.Load(#"C:\\Users\Sohaib Khalid\source\repos\SMS Degree College\Reports\AdmissionForm - Copy.rpt");
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["Other"].ConnectionString;
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("SearchStudentInfoAllById", conn);
sda.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
sda.SelectCommand.Parameters.AddWithValue("#AdmissionNumber", _admissionNumber);
sda.SelectCommand.Parameters.AddWithValue("#Active", _active);
DataSet ds = new DataSet();
sda.Fill(ds, "StudentTable");
rd.SetDataSource(ds);
admissionReportViewer.ViewerCore.ReportSource = rd;
}
}
catch(Exception err) {
this.ShowMessageAsync("No data", err.ToString());
Debug.WriteLine(err.ToString());
}
after this report also load but it again, ask for parameters:
and also credentials of server login
Can Anybody tell me why it is again asking for parameters?
Thanks
I never used ReportViewer in WPF app, but used it a couple of time on ASP.NET
If WPF works in the same way, you're code is wrong:
The report is using the data source you set up for design it and not the one you're passing to it
You're storing the parameter value in the data adapter (query) and not in the report parameters
This is why your report ask for both.
I'll share a bit of code for ASP, try to check if it can be the same for WPF or if you have to change it:
// Local mode says to use the datasource we are giving to the report
// instead of the one we used to design it
reportViewer.ProcessingMode = ProcessingMode.Local;
// Set the path of the report file
LocalReport localReport = reportViewer.LocalReport;
localReport.ReportPath = "PATH_OF_YOUR_REPORT";
// Extract data from the DB (remember to insert the parameters in the query)
var dataset = GetDataSet();
// Assign the dataset to the report source (we need a ReportDataSource)
var source = new ReportDataSource();
source.Name = "SOURCE_NAME_USED_IN_THE_REPORT";
source.Value = dataset.Tables["YOUR_TABLE"];
// Add the source to the report
localReport.DataSources.Add(source);
// Create your report parameter (ex: fromDate)
var paramFromDate = new ReportParameter();
paramDataDa.Name = "fromDate";
paramDataDa.Values.Add(paramFromDate.ToShortDateString());
// Set the report parameters for the report
localReport.SetParameters(new ReportParameter[] { fromDate });
I hope this can help you but remember, it is for ASP and not for WPF.
So try to adapt it to WPF and see if they work in the same way
I have a RDLC report with two datasets and it gives 'The definition of the report C:\Employee.rdlc' is invalid error whenever it runs. The report works fine if i only use one dataset.
Here is the setup:
For the report, i have added one datasource (i.e. Dataset) (name: 'dtsrcEmployee'' and used 'TableAdapter' to add two existing stored procedures from the existing database. In the report, i have added this dataset as DataSource. Also in report, i have added two dataset (name: dtGetEmployeeSummary, dtGetEmployeeStats) which points to two datatable from the datasource.
From the code side, i am passing dataset which has two datatable(datatable names matches with each dataset name in the Report) (i.e dtGetEmployeeSummary, dtGetEmployeeStats). Also i am using 'First' tag in report fields as mentioned here
ReportViewer reportViewer = new ReportViewer();
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.SizeToReportContent = true;
reportViewer.Width = Unit.Percentage(100);
reportViewer.Height = Unit.Percentage(100);
reportViewer.ShowZoomControl = false;
reportViewer.ShowRefreshButton = false;
reportViewer.ShowBackButton = false;
reportViewer.ShowFindControls = false;
reportViewer.LocalReport.ReportPath = reportPath;
foreach (DataTable reportTable in reportDataSet.Tables)
{
reportViewer.LocalReport.DataSources.Add(new ReportDataSource(reportTable.TableName, reportTable));
}
var resportParameterLists = new List<ReportParameter>();
foreach (var keyValuePair in parameters)
{
resportParameterLists.Add(new ReportParameter(keyValuePair.Key, keyValuePair.Value));
}
reportViewer.LocalReport.SetParameters(resportParameterLists);
reportViewer.LocalReport.Refresh();
return reportViewer;
Any idea why i am getting error while using second dataset but not while using only one?
Thanks
Update: I ended up deleting the report and created new one with two
datasets and Yes it worked this time. Not sure what was wrong with old
report.
I have created a SQL report using Visual Studio (also works when using Report Builder). The report consists of the main report with sub reports in it. When running the report via Visual Studio or Report Builder or publishing to the Report Server, it works fine and the main report and sub reports show correctly.
I have an ASP.Net MVC application which displays the report but it also allows the user to specify a where clause before running it. When the report is run via the MVC application, it shows only the main report and then says:
The subreport 'sub' could not be found at the specified location
[MVC application direcotry] Please verify that the subreport has been
published and that the name is correct.
even though the report is there.
The following is a snippet of the code which loads and displays the report:
if (ReportFileName != null && ReportFileName != "")
{
ViewBag.Title = "Reporting";
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.SizeToReportContent = true;
reportViewer.Width = Unit.Percentage(100);
reportViewer.BackColor = System.Drawing.Color.White;
reportViewer.Height = Unit.Percentage(100);
SqlConnection conx = new SqlConnection(ConfigurationManager.ConnectionStrings[""].ConnectionString);
SqlDataAdapter adp = new SqlDataAdapter(Basequery, conx);
DataTable dt = new DataTable();
adp.Fill(dt);
adp.Fill(ds.Tables[0]);
reportViewer.LocalReport.ReportPath = ReportFileName;
}
reportViewer.LocalReport.DataSources.Clear();
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("ReportDataSet", ds.Tables[0]));
reportViewer.LocalReport.Refresh();
ViewBag.ReportViewer = reportViewer;
return PartialView("ReportView");
is there something that im missing?
This is my First report using SSRS.
I am trying to generate a Report using SSRS in asp.net.
My Need is:
I want to create a report with multiple tables (4 tables) that have relationship with one another. I have configured each individual table with accepting 1 parameter, for instance:
What I tried is:
I have created a dataset.xsd with 4 tables and given the relationship between those tables.
Then I created a report.rdlc and designed a report with four tables and drag and dropped the required field to the table and created a report parameter called ID.
The error i'm Getting is:
A data source instance has not been supplied for the data source 'DataSet2'
What I have written in cs page on button click is:
protected void BtnGo_Click(object sender, EventArgs e)
{
DataSet2TableAdapters.TB_TransReceiptTableAdapter ta = new DataSet2TableAdapters.TB_TransReceiptTableAdapter();
DataSet2.TB_TransReceiptDataTable dt = new DataSet2.TB_TransReceiptDataTable();
ta.Fill(dt,Convert.ToInt16( TxtID.Text));
//ta.Fill(dt,TxtID.Text);
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet2";
rds.Value = dt;
ReportParameter rp = new ReportParameter("ID", TxtID.Text.ToString());
rptviewer.LocalReport.DataSources.Clear();
rptviewer.LocalReport.ReportPath = "Report1.rdlc";
rptviewer.LocalReport.SetParameters(new ReportParameter[] { rp });
rptviewer.LocalReport.DataSources.Add(rds);
rptviewer.LocalReport.Refresh();
rptviewer.Visible = true;
}
The help i seek is:
I dont know how to bind the report via code, since I have four tables that are related to one another with foreign key. Above is the code I used but it throws an error.
I would be very thankful if some one could help me to solve this issue.
Thanks in advance.
As per tgolisch instead of table i Bound dataset and passed to report it works fine.
And also instead of four separate table i created a view .It Makes my job simple
private DataTable getData()
{
DataSet dss = new DataSet();
string sql = "";
sql = "SELECT * from VW_TransReciptReport WHERE tREC_NUPKId='" + TxtID.Text + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.Fill(dss);
DataTable dt = dss.Tables[0];
return dt;
}
private void runRptViewer()
{
this.rptviewer.Reset();
ReportParameter rp = new ReportParameter("ID", TxtID.Text.ToString());
this.rptviewer.LocalReport.ReportPath = Server.MapPath("ReportReceipt.rdlc");
rptviewer.LocalReport.SetParameters(new ReportParameter[] { rp });
ReportDataSource rdsB = new ReportDataSource("DataSet1_VW_TransReciptReport", getData());
this.rptviewer.LocalReport.DataSources.Clear();
this.rptviewer.LocalReport.DataSources.Add(rdsB);
this.rptviewer.DataBind();
this.rptviewer.LocalReport.Refresh();
}
I have one reportviewer called reportviewer1
and two reports (report1.rdlc,report2.rdlc)
i want to display them into the reportviwer1 by choosing one of them in combo box by using the code
i tried the following code
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1"));
reportViewer1.LocalReport.ReportEmbeddedResource = "university_project.Report1.rdlc";
reportViewer1.LocalReport.Refresh();
but it didn't work
what is the correct format of the code?is there a missing parameters in the ReportDataSource?
You need to specify where the records are coming from (fill a dataSet) and set the LocalPath of the reportViewer:
var dataSet = new DataSet();
using (var connection = new SqlConnection("ConnectionString"))
{
var sqlAdapter = new SqlDataAdapter("SELECT * FROM TABLE1",connection); // Get the records
sqlAdapter.Fill(dataSet, "Table1");
}
ReportViewer1.Reset();
ReportViewer1.LocalReport.Path = "university_project.Report1.rdlc"; // Path to your report file
var dataSource = new ReportDataSource("ReportDataSet_Name", dataSet.Tables[0]); // Specify report's dataset name and the records it use
ReportViewer1.LocalReport.DataSources.Clear(); // Clean the sources so you can use different datasources each time
ReportViewer1.LocalReport.DataSources.Add(datasource);
ReportViewer1.LocalReport.Refresh();
You need to pass DataTable too:
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", myDataTableWithData));