2013-11-07 6 views
7

Я новичок в кристалле report.I разработал отчет о кристалле, следуя этой ссылке Crystal Report with SQL Stored Procedure Parameter and Visual Studio На самом деле мне нужно передать другой ID (входное значение SP) на SP, который я подключил к отчету Crystal.Передача параметра в CRYSTAL REPORT через C# в asp.net

Это код, который я передаю идентификатор для кристалла отчета:

 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; 
     } 

Но когда-либо я нажмите на кнопку она с просьбой идентификатор ... enter image description here

ответ

11

Чтобы установить параметр на кристаллическом I всегда делать это таким образом:

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.

Смежные вопросы