首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >crystal report失败

crystal report失败
EN

Stack Overflow用户
提问于 2012-07-12 16:35:11
回答 4查看 1.7K关注 0票数 0

我已经创建了一个带参数的水晶报表,但它没有加载值。它只显示标题,我的意思是只显示列名。请检查我的代码并更正我。我尝试将报告加载为pdf格式,结果显示了一个错误,如“加载报告失败”。请纠正我。

代码语言:javascript
复制
protected void Button2_Click(object sender, EventArgs e)
    {
        ReportDocument reportdocument = new ReportDocument();
        reportdocument.Load(Server.MapPath("CrystalReport.rpt"));
        reportdocument.SetDatabaseLogon("", "", "Aravind", "MySampleDB");
        reportdocument.SetParameterValue("MRNO", TextBox1.Text);
        CrystalReportViewer1.ReportSource = reportdocument;
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        EXPORTREPORT();
    }
    private void EXPORTREPORT()
    {
        MemoryStream oStream;
        Response.Clear();
        Response.Buffer = true;
        ReportDocument reportdocument = new ReportDocument();
        reportdocument.Load(Server.MapPath("CrystalReort.rpt"));
        reportdocument.SetDatabaseLogon("", "", "Aravind", "MySampleDB");
        reportdocument.SetParameterValue("MRNO",TextBox1.Text);
        CrystalReportViewer1.ReportSource = reportdocument;

        oStream = (MemoryStream)reportdocument.ExportToStream(ExportFormatType.PortableDocFormat);
        //oStream = (MemoryStream)crReport.ExportToStream(ExportFormatType.PortableDocFormat);
        Response.ContentType = "application/pdf";
        try
        {

            //write report to the Response stream

            Response.BinaryWrite(oStream.ToArray());

            Response.End();

        }

        catch (Exception ex)
        {
            Label2.Visible = true;
            Label2.Text = "ERROR:" + Server.HtmlEncode(ex.Message.ToString());


        }

        finally
        {

            //clear stream

            oStream.Flush();

            oStream.Close();

            oStream.Dispose();

        }
EN

回答 4

Stack Overflow用户

发布于 2012-07-12 16:41:23

您确定报表的名称是CrystalReort.rpt吗?而不是更常见的名称CrystalReport.rpt

它是否也位于您网站的根目录中?

票数 0
EN

Stack Overflow用户

发布于 2012-07-12 17:34:58

将值转换为必需的类型,如果其编号为Convert.ToDouble(TextBox1.Text)

票数 0
EN

Stack Overflow用户

发布于 2012-07-13 21:43:26

MRNO是什么类型的?也可以试试下面的代码,这可能会对你有所帮助。rptDoc.ExportOptions.ExportDestinationType = ExportDestinationType.NoDestination;

代码语言:javascript
复制
                Stream getStreams = rptDoc.ExportToStream(ExportFormatType.PortableDocFormat);
                byte[] getbytes = GetStreamAsByteArray(getStreams);

                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.AddHeader("Content-Length", getbytes.Length.ToString());
                Response.BinaryWrite(getbytes);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11447944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档