0

我已经编写了将 RDLC ReportViewer 与 DataSet 中的 DataTable 附加的代码

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

报表查看器的 aspx 文件代码

这是报告查看器代码

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

1 回答 1

1

在我的脑海中,我认为您的代码行说:

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

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

于 2012-07-25T07:15:04.003 回答