I use ReportViewer control on my form:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server">
</rsweb:ReportViewer>
</form>
Report file path initialized in page code file:
protected void Page_Init(object sender, EventArgs e)
{
ReportViewer1.LocalReport.ReportPath = "Reports/Source/Untitled.rdlc";
}
When report renders, I got next error:
A data source instance has not been supplied for the data source 'DataSet1'.
Connection works normally (I tested it), and when I try to run my report in MS SQL Server Report Builder - it works normally too (report was generated).
On your rdlc report there is a dataset called "DataSet1" that you have added while designing the report. You need to pass the data this Dataset will use to render the report.
This is done through the localreport datasources collection. Note that it is plural meaning you can have more than one dataset in your report.
ReportViewer1.LocalReport.DataSources.Clear();
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet1"; //this is the name of the DataSet on your report rdlc
rds.Value = datatable; //this contains the data and columns referenced in the dataset
ReportViewer1.LocalReport.DataSources.Add(rds);
If you look at the tags below you will see what the reportviewer expects
<rsweb:ReportViewer ID="ReportViewer1" runat="server">
<LocalReport ReportPath="Report1.rdlc">
<DataSources>
<rsweb:ReportDataSource Name="DataSet1" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
Update
For the second part, the datasource DataSet11 has already been declared, just reference it in the codebehind passing the data as Value
ReportViewer1.LocalReport.DataSources["DataSet1"].Value = myData;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With