0
我无法从C#表单向我的报告传递参数时遇到问题。 我有3个存储过程在sql服务器数据库MoM,它需要@MoM_ID。 起初,当我设置我的报告时,我将这些程序添加到它中,并给它们赋值339(@MoM_ID = 339)。唯一的两个选择是添加值或将其设置为NULL以继续。将参数从C#传递到Crystal Reports
设置我的报告后,我将下面的代码添加到我的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());
}
谢谢