views:

311

answers:

2

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?

+1  A: 

I would suggest setting the parameter to an actual DateTime instead of a string. The Value property of ParameterDiscreteValue takes an object. In my reports I set it to a DateTime value and it works fine. I don't work with user prompts at all, but my guess is that the parameter did not get a value it could use, and so raises the prompt.

Ray
Thanks! that was it!
Unlimited071
A: 

Yes, Crystal doesn't like strings for dates, so if it is a date field, I would pass in the date in mm/dd/yyyy format, but with a # on both end. So for today I'd pass in #04/01/2010#.

GWest