How to generate Crystal Report in PDF format while passing Multiple Parameters?

我的未来我决定 提交于 2019-12-08 07:37:18

问题


I want to generate crystal report in pdf format. I had done the same thing by passing one parameter. But this time I want to pass 10 parameter. I followed the same thing what I did for passing one parameter.

But now I got the Error Message "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." Anyone please give suggestions. Thanks in advance. Please modify my Code according to generate Crystal Report in PDF format.

In the Button Click Event I have written the following code.

try
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument rpt =
                        new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        string[] str = conn.Split(';');
        string server = str[0].Substring(str[0].IndexOf(" = ") + 3);
        string database = str[1].Substring(str[1].IndexOf(" = ") + 3);
        string userid = str[2].Substring(str[2].IndexOf(" = ") + 3);
        string password = "Welc0me";

        rpt.Load(Server.MapPath("~/Reports/Marketing/JobOrdersList.rpt"));

        for (int i = 0; i < rpt.DataSourceConnections.Count; i++)
            rpt.DataSourceConnections[i].SetConnection(server, database, userid, password);
        rpt.SetParameterValue(0, DateTime.ParseExact(dcfromdate.DateString.ToString(), DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None));
        rpt.SetParameterValue(1, DateTime.ParseExact(dcTodate.DateString.ToString(), DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None));
        rpt.SetParameterValue(2, ddlCompany.SelectedValue);
        rpt.SetParameterValue(3, ddlUnit.SelectedValue);
        rpt.SetParameterValue(4, ddlCustomer.SelectedValue);
        rpt.SetParameterValue(5, ddlProduct.SelectedValue);
        rpt.SetParameterValue(6, ddlScope.SelectedValue);
        rpt.SetParameterValue(7, ddlStatus.SelectedValue);
        rpt.SetParameterValue(8, ddlGroupBy.SelectedValue);
        rpt.SetParameterValue(9, (ChkPrint.Checked == true ? "True" : "False"));
        rpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, HttpContext.Current.Response, true, "JobOrderList Report");

    }
    catch (Exception ex)
    {
        return ex.Message.ToString();
    }

回答1:


//To generate PDF dynamically 

using System;
    using System.Windows.Forms;
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;

    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            ReportDocument cryRpt;

            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                cryRpt = new ReportDocument();
                cryRpt.Load(PUT CRYSTAL REPORT PATH HERE\\CrystalReport1.rpt");
                crystalReportViewer1.ReportSource = cryRpt;
                crystalReportViewer1.Refresh(); 
            }

            private void button2_Click(object sender, EventArgs e)
            {
                try
                {
                    ExportOptions CrExportOptions ;
                    DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                    PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                    CrDiskFileDestinationOptions.DiskFileName = "c:\\csharp.net-informations.pdf";
                    CrExportOptions = cryRpt.ExportOptions;
                    {
                        CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                        CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                        CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                        CrExportOptions.FormatOptions = CrFormatTypeOptions;
                    }
                    cryRpt.Export();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
    }


来源:https://stackoverflow.com/questions/5104381/how-to-generate-crystal-report-in-pdf-format-while-passing-multiple-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!