簡體   English   中英

通過asp.net中的C#將參數傳遞給CRYSTAL REPORT

[英]passing parameter to the CRYSTAL REPORT through C# in asp.net

我是水晶報告的新手。我通過以下鏈接設計了水晶報告Crystal Report與SQL存儲過程參數和Visual Studio實際上我需要將不同的ID(SP的輸入值)傳遞給我與Crystal連接的SP報告。

這是我將ID傳遞給水晶報告的代碼:

        protected void Button1_Click(object sender, EventArgs e)
        {
        string QuotationID = ViewState["QUOTATION_ID"].ToString();
        ReportDocument reportDocument = new ReportDocument();
        ParameterField paramField = new ParameterField();
        ParameterFields paramFields = new ParameterFields();
        ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();



        paramField.Name = "@id";


        paramDiscreteValue.Value = QuotationID;

        paramField.CurrentValues.Add(paramDiscreteValue);
        paramFields.Add(paramField);


        paramFields.Add(paramField);

        CrystalReportViewer1.ParameterFieldInfo = paramFields;

        string reportPath = Server.MapPath("~/CrystalReport.rpt");

        reportDocument.Load(reportPath);


        CrystalReportViewer1.ReportSource = reportDocument;
        }

但是當我點擊按鈕時它會詢問ID ... 在此輸入圖像描述

要在水晶上設置參數,我總是這樣做:

ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(reportPath);
reportDocument.SetParameterValue("@id", QuotationID);

如果您想將報告轉換為pdf:

var exportOptions = reportDocument.ExportOptions;
exportOptions.ExportDestinationType = ExportDestinationType.NoDestination;
exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
var req = new ExportRequestContext {ExportInfo = exportOptions};
var stream = reportDocument.FormatEngine.ExportToStream(req);

這將返回一個您可以從aspx頁面打開的文件流。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM