cancel
Showing results for 
Search instead for 
Did you mean: 

Issues Setting DateTime Parameter Value

DellSC
Active Contributor
0 Kudos

Window Server 2003 - 32-bit

.NET SDK BO 4.0 SP9 - can't be upgraded because of the requirement to run on Win 2003.

.NET Framework 3.5

Visual Studio 2010

I'm upgrading a client's website code from 3.1 to 4.0 but I'm having an issue in the functionality for saving a copy of a Crystal Report that's already in the system but which has been "personalized" with a user defined set of default parameter values.  All of this is working fine as long as the parameter data type is either string or number.  However, if the parameter data type is date or datetime, I get a "One or more arguments are invalid" error.  Originally, this was just setting the value for everything as if it were a string.  So, for dates it was passing something like "10/17/2014".  This apparently worked in 3.1, but is throwing the error in 4.0.  So, I tried using this code to update the value:

    private string getValue(CrystalDecisions.Enterprise.Desktop.CeReportVariableValueType valType, string value)

    {

      string result = "";

      if (valType == CrystalDecisions.Enterprise.Desktop.CeReportVariableValueType.ceRVDate)

      {

        result = string.Format("Date('{0}')", value);

      }

      else if (valType == CrystalDecisions.Enterprise.Desktop.CeReportVariableValueType.ceRVDateTime)

      {

        result = string.Format("DateTime('{0}')", value);

      }

      else if (valType == CrystalDecisions.Enterprise.Desktop.CeReportVariableValueType.ceRVTime)

      {

        result = string.Format("Time('{0}')", value);

      }

      else

      {

        result = value;

      }

      return result;

    }

And here is the code that sets the parameter value:

              if (prompt.AllowDiscreteValues)

              {

                // Discrete(not ranges)

                if (prompt.LowerValue.Count > 0)

                {

                  ReportParameterValue paramValue = param.CreateSingleValue();

                  value = getValue(param.ValueType, prompt.LowerValue[0].Value);

                  //value = prompt.LowerValue[0].Value;

                  paramValue.SingleValue.Value = value;

                  paramValue.SingleValue.Description = prompt.LowerValue[0].Description;

                  if (string.IsNullOrEmpty(paramValue.SingleValue.Description))

                    paramValue.SingleValue.Description = prompt.LowerValue[0].Value;

                  param.CurrentValues.Add(paramValue);

                  param.DefaultValues.Add(paramValue);

                }

              }

Does anyone have any thoughts about what I to do here?

Thanks!

-Dell

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Hi Dell,

Use this format:

rpt.SetParameterValue("pcname", Convert.ToDateTime(parmPCname));

Have a great weekend

Don

DellSC
Active Contributor
0 Kudos

Thanks Don, but doesn't that just set the current value of the param for running the report?  I'm trying to set the default value of the parameter prior to saving the report to BO.  Also, I'm working with an InfoObject that I've cast to a "Report", not a ReportDocument.

-Dell

Message was edited by: Dell Stinnett-Christy

0 Kudos

Hi Dell,

Yes it does but the point is defining the type by using this:

Convert.ToDateTime()

So you should be using that property for any type:

rpt.SetParameterValue("pcname", Convert.ToDateTime(parmPCname));

rpt.SetParameterValue("pcname", Convert.ToDecimal(parmPCname));

rpt.SetParameterValue("pcname", Convert.ToInt32(parmPCname));

rpt.SetParameterValue("pcname", Convert.ToString(parmPCname));

Hope that helps?

Don

DellSC
Active Contributor
0 Kudos

But my point is that I don't have a ReportDocument object, I'm working with an InfoObject that has been cast as a Report because I'm copying an existing report from BO to a new report.  So, I don't think I have access to the SetParameter() method.  The ReportParameterValue.SingleValue.Value property that I'm using is a string and it's throwing an error when you pass a date string into it - I've tried a number of formats, but they all throw an error:

<date string>

HttpUtility.URLDecode(<date string>)  <-- This matches the original code

Date(<date string>) or DateTime(<date string>)


The date string is in the format "MM/dd/yyyy" and the datetime string is in the format "MM/dd/yyyy hh:nn:ss AM"

I'm working with a different client this week, so I don't have access to this code during the day.  However, I'll play with this some more this evening and see if I can get to the "SetParameterValue" method this evening when I get back to my hotel.

-Dell

Former Member
0 Kudos

I am having the same issue with my code. Did you ever find a solution to the issue? When I try to set the parameter value for a datetime parameter, I get this error "One or more arguments are invalid" on the parmValue.SingleValue.Value = dateParm line.

            //Setting Report parameters

            ReportParameters reportParameters = report.ReportParameters;

            for (int i = 1; i <= reportParameters.Count; i++)

            {

                ReportParameter reportParameter = reportParameters[i];

                reportParameter.CurrentValues.Clear();

                ReportParameterValue parmValue = reportParameters[i].CreateSingleValue();

              

                if (reportParameter.ValueType == CeReportVariableValueType.ceRVDateTime)

                {

                    var dateParm = string.Format("DateTime(" + parameters[i - 1].ToString().Replace("/", ", ") + ", 00, 00, 00)");

                    parmValue.SingleValue.Value = dateParm;

                }

                else if (reportParameter.ValueType == CeReportVariableValueType.ceRVDate)

                {

                    var dateParm = "DateTime(" + parameters[i - 1].ToString().Replace("/", ", ") + ")";

                    parmValue.SingleValue.Value = dateParm;

                }

                else

                {

                    parmValue.SingleValue.Value = parameters[i - 1].ToString();

                }

                reportParameter.CurrentValues.Add(parmValue);

            }

Thanks,

Angela