【发布时间】:2015-08-18 06:20:12
【问题描述】:
我在将参数从 C# 表单传递到我的报告时遇到问题。 我在 sql server 数据库 MoM 中有 3 个存储过程,它们需要 @MoM_ID。 起初,当我设置我的报告时,我将这些程序添加到其中并给它们值 339 (@MoM_ID = 339)。仅有的两个选项是添加该值或将其设置为 NULL 以继续。
设置报告后,我将以下代码添加到我的 C# 表单中,该代码在单击按钮时发生。代码应将参数传递给存储过程,并将报告输出为 pdf 文件,其中包含报告中的新值。但是,当我这样做时,我总是在报告中得到相同的默认值,其中@MoM_ID 等于 339。
这是代码:
ReportDocument reportDocument = new ReportDocument();
ParameterField paramField = new ParameterField();
ParameterFields paramFields = new ParameterFields();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
//Set instances for input parameter 1 - @Dept
paramField.Name = "@MoM_ID(Action_Items)";
//*Remember to reconstruct the paramDiscreteValue and paramField objects
paramDiscreteValue.Value = "337";
paramField.CurrentValues.Add(paramDiscreteValue);
//Add the paramField to paramFields
paramFields.Add(paramField);
crystalReportViewer1.ParameterFieldInfo = paramFields;
reportDocument.Load(@"C:\Users\nbousaba\Documents\Visual Studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Report1.rpt");
//Load the report by setting the report source
crystalReportViewer1.ReportSource = reportDocument;
crystalReportViewer1.Refresh();
//set the database loggon information.
reportDocument.SetDatabaseLogon("//USERNAME", "//PW", "//IP", "MoM");
//Creating a PDF file from the Crystal Report
try
{
ExportOptions CrExportOptions ;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = "c:\\testing123.pdf";
CrExportOptions = reportDocument.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
reportDocument.Export();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
谢谢
【问题讨论】:
标签: c# .net sql-server reporting-services crystal-reports