Forum Moderators: open

Message Too Old, No Replies

passing parameter values when exporting report

parameter passing to report

         

BroncosRule

12:50 pm on Oct 6, 2003 (gmt 0)

10+ Year Member



I code in C#:

I have an application that generates 4 different Crystal Reports. Two of these reports have some parameter fields on them. I chose to create session variables in the Global file. These session variables get populated when a user selects various values from drop down boxes in the beginning of the application. I utilized CrystalDecisions.Shared.ParameterFields to code the Crystal report parameters to automatically populate from the session variables to avoid any more user interaction. This works fine. My problem is when I try to export the crystal report to excel format. I have successfully coded the application to export the two crystal reports that do NOT have any parameter fields in them, but when I try to export the two reports that do have parameter fields, I get "MISSING PARAMETER FIELD CURRENT VALUE". Do you know how to pass the parameter values from the Crystal Report into the exported excel document?

Any help would be appreciated.
Here is some code I am utilizing:

InitializeComponent();
base.OnInit(e);
oRpt = new TrendStateWideReport();
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["SqlServer.ADO"]);
SqlDataAdapter sda = new SqlDataAdapter("TrendStateWide_TEST_BRIAN", con);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
sda.SelectCommand.Parameters.Add(new SqlParameter("@YearName" ,SqlDbType.VarChar,50)).Value= Request.QueryString["YearName"].ToString();
sda.SelectCommand.Parameters.Add(new SqlParameter("@Cluster" ,SqlDbType.VarChar,50)).Value= Request.QueryString["Cluster"].ToString();
dsTrendStateWide dataSet = new dsTrendStateWide();
sda.Fill(dataSet, "TrendStateWide_view");
oRpt.SetDataSource (dataSet);
//***Start of setting report parameter values for year headings on the crystal report***
CrystalDecisions.Shared.ParameterFields ParameterFields;
CrystalDecisions.Shared.ParameterField ParameterField, ParameterField1, ParameterField2;
CrystalDecisions.Shared.ParameterDiscreteValue ParameterDiscreteValue, ParameterDiscreteValue1, ParameterDiscreteValue2;
//Create a new ParameterFields collection
ParameterFields = new CrystalDecisions.Shared.ParameterFields();
//Creata a new ParameterField object
ParameterField = new CrystalDecisions.Shared.ParameterField();
ParameterField1 = new CrystalDecisions.Shared.ParameterField();
ParameterField2 = new CrystalDecisions.Shared.ParameterField();
//Assign the ParameterFieldName property
ParameterField.ParameterFieldName = "YearSelected";
ParameterField1.ParameterFieldName = "YearSelected1";
ParameterField2.ParameterFieldName = "YearSelected2";
//Create a ParameterValue object
ParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();
ParameterDiscreteValue1 = new CrystalDecisions.Shared.ParameterDiscreteValue();
ParameterDiscreteValue2 = new CrystalDecisions.Shared.ParameterDiscreteValue();
//Assign a value to the object
ParameterDiscreteValue.Value = Session["YearSelected"];
ParameterDiscreteValue1.Value = Session["YearSelected1"];
ParameterDiscreteValue2.Value = Session["YearSelected2"];
//Add the ParameterValue object to either the CurrentValues or DefaultValues collection
ParameterField.CurrentValues.Add(ParameterDiscreteValue);
ParameterField1.CurrentValues.Add(ParameterDiscreteValue1);
ParameterField2.CurrentValues.Add(ParameterDiscreteValue2);
//Add the ParameterField object to the ParameterFileds collection
ParameterFields.Add(ParameterField);
ParameterFields.Add(ParameterField1);
ParameterFields.Add(ParameterField2);
//Assign the ParameterFields collection to the viewer
CrystalReportViewer1.ParameterFieldInfo = ParameterFields;
CrystalReportViewer1.ReportSource = oRpt;
if (Session ["Excel"] == "1")
{
Session ["Excel"] = "0";
//***Beginning of export process***
//Declare variables and get the export options
ExportOptions exportOpts = new ExportOptions ();
ExcelFormatOptions excelFormatOpts = new ExcelFormatOptions ();
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions ();
exportOpts = oRpt.ExportOptions;

//Set the excel format options
excelFormatOpts.ExcelUseConstantColumnWidth = true;
exportOpts.ExportFormatType = ExportFormatType.Excel;
exportOpts.FormatOptions = excelFormatOpts;

//Set the disk file options and export
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
diskOpts.DiskFileName = "C:\\exportExcel" + Session.SessionID + ".xls";
exportOpts.DestinationOptions = diskOpts;

oRpt.Export ();

//Show excel file in browser
Response.Redirect((string)diskOpts.DiskFileName);
}
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

wardbekker

2:00 pm on Oct 22, 2003 (gmt 0)

10+ Year Member



This is very Crystal Reports specific, you might be better of asking this question in their support groups. Although it never hurts to ask, somebody might just know the answer ;-)