0

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

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

        }
4

4 回答 4

0

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

                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);
于 2012-07-13T13:43:25.743 回答
0

你确定你的报告的名字是CrystalReort.rpt?而不是一个更常见的名字CrystalReport.rpt

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

于 2012-07-12T08:41:23.473 回答
0

将值转换为所需类型,如果它的数字则 Convert.ToDouble(TextBox1.Text)

于 2012-07-12T09:34:58.173 回答
0

在页面的加载事件中编写以下代码。

if (crystalReportDoc != null)
        {
            crystalReportDoc.Close();
            crystalReportDoc.Dispose();
            GC.Collect();
        }
于 2016-11-18T12:21:35.447 回答