在 asp.net 中通过 C# 将参数传递给 CRYSTAL REPORT

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19838307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 15:57:57  来源:igfitidea点击:

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

c#asp.netsql-servercrystal-reports

提问by user2536023

I am new to crystal report.I have designed the crystal report by following this link Crystal Report with SQL Stored Procedure Parameter and Visual StudioActually i need to pass different ID(Input value of the SP) to the SP that i connected with the Crystal report.

我是水晶报表的新手。我按照此链接设计水晶报表 带有 SQL 存储过程参数和 Visual Studio 的水晶报表实际上我需要将不同的 ID(SP 的输入值)传递给我与水晶连接的 SP报告。

This is the Code that i am Passing the ID to crystal report :

这是我将 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;
        }

But when ever i click the button it asking the ID ...enter image description here

但是当我点击按钮时,它会询问 ID ......在此处输入图片说明

采纳答案by Raphael

To set parameter on crystal I always do it this way:

要在水晶上设置参数,我总是这样做:

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

if you want to convert your report to a pdf:

如果您想将报告转换为 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);

this returns you back a filestream that you can open from the aspx page.

这会返回一个可以从 aspx 页面打开的文件流。