在asp.net中传递参数的水晶报表通过C# [英] passing parameter to the CRYSTAL REPORT through C# in asp.net

查看:529
本文介绍了在asp.net中传递参数的水晶报表通过C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的晶体report.I已经通过以下链接<一所设计的水晶报表href=\"http://dotnetmentors.com/reporting/crystal-report-with-stored-procedure-parameter-and-visual-studio.aspx\"相对=nofollow>水晶报表与SQL存储过程参数和Visual Studio
其实我需要通过不同的ID(SP的输入值),我与Crystal报表连接SP。

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 Studio Actually i need to pass different ID(Input value of the SP) to the SP that i connected with the Crystal report.

这是code是我传递的​​ID来水晶报表:

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

        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按钮...

But when ever i click the button it asking the ID ...

推荐答案

要设置晶体参数,我总是做这种方式:

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

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

如果您希望您的报表转换为PDF格式:

if you want to convert your report to a 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);

这将返回回FILESTREAM,你可以从aspx页面打开。

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

这篇关于在asp.net中传递参数的水晶报表通过C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆