Answered by:
Local Report DataSource

Question
-
User838104837 posted
I am trying to learn how to do Local Reports is VS 2012. I have the Client-Side reporting book and am trying to get the 1st example to work. When I try to run it I get this error: A data source instance has not been supplied for the data source 'DataSet1'.
ReportViewer1.LocalReport.DataSources.Clear();
//prepare report data source
ReportDataSource rds = new ReportDataSource();
rds.Name = "dsAgedAR_dtAgedAR";
rds.Value = dsReport.Tables[0];
ReportViewer1.LocalReport.DataSources.Add(rds);I don't understand the error or what to do about it. I can find DataSet1 in the XML for the Report so it must be some built-in thing but it seems like it should be overwritten by the assignment above.
Wednesday, June 12, 2013 9:30 AM
Answers
-
User838104837 posted
Well this was easy. It ONLY took 3 days of searching Google. Not that this actually worked before until Microsoft "IMPROVED" it and broke it in VS 2010. I still don't understand why it works like this but I found a fix. Even though the DataSet that I created and attached to the report is called dsAgedAR the report is hung up on DataSet1. So we give it what it wants
The key is: ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dsReport.Tables[0]));
Here is more code:
if (!IsPostBack)
{
//Declare connection string
string cnString = "Data Source=PROGDEV\\SQLEXPRESS;Initial Catalog=RealWorld;Integrated Security=SSPI;";//Declare Connection, command and other related objects
SqlConnection conReport = new SqlConnection(cnString);
SqlCommand cmdReport = new SqlCommand();
SqlDataReader drReport;
DataSet dsReport = new dsAgedAR();try
{
conReport.Open();cmdReport.CommandType = CommandType.Text;
cmdReport.Connection = conReport;
cmdReport.CommandText = "Select * FROM dbo.AgedAR order by CustomerName, InvoiceNo";drReport = cmdReport.ExecuteReader();
dsReport.Tables[0].Load(drReport);drReport.Close();
conReport.Close();
//provide local report information to viewer
ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dsReport.Tables[0]));
ReportViewer1.LocalReport.Refresh();
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 14, 2013 8:25 AM
All replies
-
User838104837 posted
Well this was easy. It ONLY took 3 days of searching Google. Not that this actually worked before until Microsoft "IMPROVED" it and broke it in VS 2010. I still don't understand why it works like this but I found a fix. Even though the DataSet that I created and attached to the report is called dsAgedAR the report is hung up on DataSet1. So we give it what it wants
The key is: ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dsReport.Tables[0]));
Here is more code:
if (!IsPostBack)
{
//Declare connection string
string cnString = "Data Source=PROGDEV\\SQLEXPRESS;Initial Catalog=RealWorld;Integrated Security=SSPI;";//Declare Connection, command and other related objects
SqlConnection conReport = new SqlConnection(cnString);
SqlCommand cmdReport = new SqlCommand();
SqlDataReader drReport;
DataSet dsReport = new dsAgedAR();try
{
conReport.Open();cmdReport.CommandType = CommandType.Text;
cmdReport.Connection = conReport;
cmdReport.CommandText = "Select * FROM dbo.AgedAR order by CustomerName, InvoiceNo";drReport = cmdReport.ExecuteReader();
dsReport.Tables[0].Load(drReport);drReport.Close();
conReport.Close();
//provide local report information to viewer
ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dsReport.Tables[0]));
ReportViewer1.LocalReport.Refresh();
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 14, 2013 8:25 AM -
User260886948 posted
Hi,
I am very glad that you have solved your problem by yourself.
If you have any other problem, welcome to post it in the asp.net forums.
Best Regards,
Amy PengTuesday, June 18, 2013 9:58 PM