Hello Readers. I have developed a web based inventory and accounts system application using Sql Server 2008, Asp.net using c#.net. I have used crystal reports for reporting. Everything on reporting side is working fine. Yesterday i came across , that my parameters on the report were not getting refreshed which were initially working absolutely fine.
I give you are scenario and will present the code to analyise e.g i am running a report that contains ParamDate1 and ParaDate2 parameters in crystal reports which i want to use to show on the report. The values are getting pass to these parameters using controls and code for this is
ReportDocument RptDoc;
ParameterFieldDefinition PFD;
ParameterValues PV;
ParameterDiscreteValue PDV;
private void SetDate1AndDate2Parameters(ReportDocument RptDoc) { //Date 1 Parameters PV = new ParameterValues(); PDV = new ParameterDiscreteValue(); PFD = RptDoc.DataDefinition.ParameterFields["ParamDate1"]; PDV.Value = Convert.ToDateTime(Date1TextBox.Text); PV.Add(PDV); PFD.ApplyCurrentValues(PV); //Date 2 PV = new ParameterValues(); PDV = new ParameterDiscreteValue(); PFD = RptDoc.DataDefinition.ParameterFields["ParamDate2"]; PDV.Value = Convert.ToDateTime(Date2TextBox.Text); PV.Add(PDV); PFD.ApplyCurrentValues(PV); }
Now the code that runs the report is under the following
switch(ReportTitleHiddenField.Value) { case "CostOfGoodsSold": ReportPath = "~/Reports/CostOfGoodsSold.rpt"; DataSet CostOfGoodsSoldDS = FillCostOfGoodsSold(); RptDoc = new ReportDocument(); RptDoc.Load(Server.MapPath(ReportPath)); RptDoc.SetDataSource(CostOfGoodsSoldDS); RptDoc.Subreports[0].SetDataSource(FillHeadersReportInfo()); SetDate1AndDate2Parameters(RptDoc); //SetCurrencyAndRateParameters(RptDoc); //SetMethodParameter(RptDoc); CrystalReportViewer1.ReportSource = RptDoc; CreateLog(RptDoc.SummaryInfo.ReportTitle, "From Date : " + Date1TextBox.Text.Trim() + " To Date : " + Date2TextBox.Text.Trim() + " Currency : " + CurrencyDDL.SelectedValue + " Rate : " + GetCurrentCurrencyRate()); break; }
The report run aboslutely fine with this code. now problem here is when i run this for the first time. parameters do get values what i select and show them on the report perfectly but they are not show the subsequent times instead it shows the same old values that were selected on the first run.
I do know the alternative for this to use i.e.
ParameterFields PFs = new ParameterFields(); ParameterField PFDate1 = new ParameterField(); ParameterDiscreteValue PDVDate1 = new ParameterDiscreteValue(); PFDate1.Name = "ParamDate1"; PDVDate1.Value = Convert.ToDateTime(Date1TextBox.Text.Trim()); PFDate1.CurrentValues.Add(PDVDate1); PFs.Add(PFDate1); ParameterField PFDate2 = new ParameterField(); ParameterDiscreteValue PDVDate2 = new ParameterDiscreteValue(); PFDate2.Name = "ParamDate2"; PDVDate2.Value = Convert.ToDateTime(Date2TextBox.Text.Trim()); PFDate2.CurrentValues.Add(PDVDate2); PFs.Add(PFDate2); CrystalReportViewer1.ParameterFieldInfo = PFs;
But I want to know that what is wrong with my code that was working fine before. plus. when using this above mentioned approach i have to handle some crystal report viewer event to give parameters their values as my report page do post back on ChangeParameterOption, Refresh,Export which i am doing manually in the code.
I am waiting for you guidance in this. Thanks in advance.