I have created a custom control (a windows form with a report viewer). I have the following code to load a local report:
Contained in CustomReportViewer Clas
The key for me was as answered by StuartLC as above... with further clarification in that when he said it "Must match the DataSource in the RDLC".. it actually turned out to be the "DataSetName" element value re:
I went round and round because it is called "DataSource" so I kept using the DataSource element name but apparently in the rdl and rdlc file this really signifies the DataSetName. So keeping that in mind here is the code as borrowed from Stuart above with my own. Note the DataSetName element value:
using (SqlConnection sqlConn = new SqlConnection(rvConnection))
using (SqlDataAdapter da = new SqlDataAdapter(rvSQL, rvConnection))
{
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
this.reportViewer1.Reset();
this.reportViewer1.ProcessingMode = ProcessingMode.Local;
this.reportViewer1.LocalReport.ReportPath = AppDomain.CurrentDomain.BaseDirectory + "ssrsExport.rdlc";
ReportDataSource reportDataSource = new ReportDataSource();
// Must match the DataSet in the RDLC
reportDataSource.Name = "DataSet1";
reportDataSource.Value = ds.Tables[0];
this.reportViewer1.LocalReport.DataSources.Add(reportDataSource);
this.reportViewer1.RefreshReport();
}