首页 文章

C#RDLC报告错误

提问于
浏览
0

我编写了代码,用于将RDLC ReportViewer与DataSet中的DataTable连接起来

但是会发生此错误:“尚未为数据源'DataSet'提供数据源实例 . ”

报表查看器的aspx文件代码

这是Report Viewer代码

<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#文件代码

这是用于填充DataSet中的DataTable行的代码

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

        }

这是将数据源提供给报表查看器的代码

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

1 回答

  • 1

    在我的头脑中,我认为你的代码行说:

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

    基本上它与您在RDLC文件中使用的名称有关,当您提供报告数据集时,它必须命名为相同的名称 .

相关问题