How to pass date parameters to Crystal Reports 2008 from an ASP.NET App?

Posted by Unlimited071 on Stack Overflow See other posts from Stack Overflow or by Unlimited071
Published on 2010-03-31T19:50:24Z Indexed on 2010/03/31 19:53 UTC
Read the original article Hit count: 282

Filed under:
|

Hello all,

I'm passing some parameters to a CR report programatically and it was working fine, but now that I have added a new date parameter to the report, for some reason, it is prompting me to enter that parameter on screen (the user isn't allowed to set that parameter is the system who must set it.), I haven't changed a thing other than adding the new date parameter, and all the other parameters behave normal, just the date parameter is prompted even thought I've already set a value for the parameter.

This is the code I've got:

private void ConfigureCrystalReports()
{
    crystalReportViewer.ReportSource = GetReportPath();
    crystalReportViewer.DataBind();

    ConnectionInfo connectionInfo = GetConnectionInfo();
    TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo;
    foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos) {
        tableLogOnInfo.ConnectionInfo = connectionInfo;
    }

    ArrayList totOriValues = new ArrayList();
    totOriValues.Add(date.ToString("MM/dd/yyyy HH:mm:ss")); 
    ParameterFields parameterFields = crystalReportViewer.ParameterFieldInfo;
    SetCurrentValuesForParameterField(parameterFields, totOriValues, "DateParameter");
}

private static void SetCurrentValuesForParameterField(ParameterFields parameterFields, ArrayList arrayList, string parameterName)
{
    ParameterValues currentParameterValues = new ParameterValues();
    foreach (object submittedValue in arrayList) {
        ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
        parameterDiscreteValue.Value = submittedValue.ToString();
        currentParameterValues.Add(parameterDiscreteValue);
    }

    ParameterField parameterField = parameterFields[parameterName];
    parameterField.CurrentValues = currentParameterValues;
}

Just for the sake of things: I have checked that the parameter is indeed a date and that it is well formed. CR prompts me to enter it in the format (mm/dd/yyyy hh:mm:ss) so I pass date in that exact format (In fact I've even tried hard coding a well-formed date and it still prompts me to enter the date).

Am I doing something wrong?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about crystal-reports