0

I have writen code for to attach RDLC ReportViewer with a DataTable from a DataSet

But this error occurs: "A data source instance has not been supplied for the data source 'DataSet'."

aspx file code for Report Viewer

This is Report Viewer code

 <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
     Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
     WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
     <ServerReport ReportPath="Analysis.rdlc" />
     <LocalReport ReportPath="Hospital\Analysis.rdlc">
     </LocalReport>
 </rsweb:ReportViewer>

C# File Code

This is code to fill Rows of DataTable in DataSet

        ArrayList columns = new ArrayList();
        columns.Add("Temp");
        columns.Add("Humidity");
        columns.Add("Rain");
        columns.Add("Mosquitos");
        columns.Add("FloodArea");
        columns.Add("CloudyWeather");
        columns.Add("FlowerVases");
        columns.Add("IndequateSanitation");
        ArrayList data = new ArrayList();
                    data.Add(Temp.SelectedItem.ToString());
        data.Add(Humidity.SelectedItem.ToString());
        data.Add(Rain.SelectedItem.ToString());
        data.Add(Mosquitos.SelectedItem.ToString());
        data.Add(FloodArea1.SelectedItem.ToString());
        data.Add(CloudyWeather.SelectedItem.ToString());
        data.Add(FlowerVases.SelectedItem.ToString());
        data.Add(IndequateSanitation.SelectedItem.ToString());
        BayesAnalysis bAnlysis = new BayesAnalysis();
        ArrayList result = bAnlysis.classifyD(DiseaseList.SelectedItem.ToString(), columns, data);
        List<double> pn = bAnlysis.PosNum();
        NormalAnalysis nAnalysis = new NormalAnalysis();
        AnalysisDataSet dss = new AnalysisDataSet();
        for (int loop = 0; loop < pn.Count; loop++)
        {
            dss.ReportData.AddReportDataRow(loop, result[loop].ToString(), nAnalysis.NoPatient(nAnalysis.GetDiseaseID("Dengue"), nAnalysis.GetCityID(result[loop].ToString())), nAnalysis.TotalPatient(nAnalysis.GetDiseaseID("Dengue")), nAnalysis.diseasePercentageInCity(nAnalysis.GetDiseaseID("Dengue"), nAnalysis.GetCityID(result[loop].ToString())), pn[loop]);

        }

This is code to Give Data Source to the Report Viewer

        DataTable dtt = dss.ReportData;
        ReportViewer1.Visible = true;
        ReportDataSource datasource = new ReportDataSource("Analysis",dtt);
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(datasource);
        ReportViewer1.LocalReport.Refresh();
MatthewMartin
  • 32,326
  • 33
  • 105
  • 164

1 Answers1

1

Of the top of my head I think your line of code that says :

ReportDataSource datasource = new ReportDataSource("Analysis",dtt);
ReportDataSource datasource = new ReportDataSource("DataSet",dtt);

Basically it is to do with a name that you used in the RDLC file and when you supply the report dataset it must be named the sames.

Stephan
  • 41,764
  • 65
  • 238
  • 329
Tom
  • 21
  • 5