报告处理期间发生错误。无法为数据集创建datareader

时间:2014-10-17 20:33:46

标签: c# pdf visual-studio-2012 reportviewer rdlc

我花了大约两天的时间在这上面,我的智慧结束了。这是场景,我有一个rdlc报告,如果选中,它会在新窗口中呈现完美。我想要完成的是让rdlc自动导出并下载PDF版本,如果选择了该选项。下面是页面的代码以及我要做的事情。我尝试了多种方法来导出PDF,但我不断得到标题中所述的相同错误。错误发生在行byte [] bytes = etc等上。 非常感谢任何帮助。

 if (!Page.IsPostBack)
            {
                string orgName = Request.QueryString["orgName"];
                long orgID = Convert.ToInt64(Request.QueryString["orgID"]);
                long yearID = Convert.ToInt64(Request.QueryString["yearID"]);
                long verID = Convert.ToInt64(Request.QueryString["verID"]);
                long prevYearID = Convert.ToInt64(Request.QueryString["prevYearID"]);
                long prevVerID = Convert.ToInt64(Request.QueryString["prevVerID"]);
                string oh = Request.QueryString["oh"];
                string pack = Request.QueryString["pack"];


                string iyearID = yearID.ToString();


                ReportParameter pyID = new ReportParameter("pyearID", iyearID);
                this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { pyID });
                ReportParameter poName = new ReportParameter("porgName", orgName);
                this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { poName });
                if (verID == 1)
                {
                    ReportParameter bver = new ReportParameter("pbudVer", "Bid");
                    this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { bver });
                }
                else if (verID == 2)
                {
                    ReportParameter bver = new ReportParameter("pbudVer", "First Draft");
                    this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { bver });
                }
                else if (verID == 3)
                {
                    ReportParameter bver = new ReportParameter("pbudVer", "Final Draft");
                    this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { bver });
                }
                else if (verID == 4)
                {
                    ReportParameter bver = new ReportParameter("pbudVer", "1st Reforecast");
                    this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { bver });
                }
                else if (verID == 5)
                {
                    ReportParameter bver = new ReportParameter("pbudVer", "2nd Reforecast");
                    this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { bver });
                }
                else if (verID == 6)
                {
                    ReportParameter bver = new ReportParameter("pbudVer", "3rd Reforecast");
                    this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { bver });
                }
                else if (verID == 7)
                {
                    ReportParameter bver = new ReportParameter("pbudVer", "4th Reforecast");
                    this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { bver });
                }

                if (pack == "Y")
                {
                    //trythis1();
                    createPdfReport();

                    //SavePDF(Org_Summary);

                }
            }
        }
        catch (Exception err)
        {

        }


    }

    public void createPdfReport()
    {
        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string filenameExtension;


        byte[] bytes = this.ReportViewer1.LocalReport.Render(
            "PDF", null, out mimeType, out encoding, out filenameExtension,
            out streamids, out warnings);

        using (FileStream fs = new FileStream("output.pdf", FileMode.Create))
        {
            fs.Write(bytes, 0, bytes.Length);
        }

    }

0 个答案:

没有答案