Error while getting multiple Datasets in RDLC report - c#

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.

Related

SQL report with subreport not showing on page

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?

How do I connect Crystal reports to multiple database?

I have a webpage which has a drop-down. In the drop-down there is a list of databases from a server. On selecting the drop-down document numbers are shown and we can click and generate crystal report.
My problem is I have given data-source for one database in the crystal report. Suppose I select other databases. How can I connect to the report for multiple databases?
Any inputs will be greatly appreciated.
Are you using CR designer or Visual Studio to make your reports? Because there is a connection section in the field explorer window. Generally, it is not recommend to connect to multiple DB. Even if you are using for example 2 or more stored procedures for your report, you can complicate your life if they don't have a common key.
The below is what we use, it should work for you. Basically you have to make sure that for every table the report accesses (or command, or view, etc.), the connection is set. I'm not aware of a way to set it only on the main report.
// create a ReportDocument
using (ReportDocument reportDoc = new ReportDocument())
{
reportDoc.Load(path); // path to your .rpt file
// get the connection string you want to use
SqlConnectionStringBuilder conInfo = new SqlConnectionStringBuilder("<your connection string>");
Tables crTables = reportDoc.Database.Tables;
int tablecounter = 0;
foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
CrystalDecisions.Shared.TableLogOnInfo logonInfo = crTable.LogOnInfo;
logonInfo.ConnectionInfo = new ConnectionInfo()
{
DatabaseName = conInfo.InitialCatalog,
ServerName = conInfo.DataSource
};
if (conInfo.IntegratedSecurity)
{
logonInfo.ConnectionInfo.IntegratedSecurity = true;
}
else
{
logonInfo.ConnectionInfo.UserID = conInfo.UserID;
logonInfo.ConnectionInfo.Password = conInfo.Password;
}
crTable.ApplyLogOnInfo(logonInfo);
}
}

A data source instance has not been supplied for the data source 'DataSet2'-SSRS

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();
}

two reports in one reportViewer

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));

Unable to bind datasource to reportViewer

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

Categories