Why does it generate an "Invalid parameter value" error message when I pass an argument of type DATE to crystal reports?

This code works fine on my computer, but causes an error on the client computer.

cr.SetParameterValue("fromDate", fromDatePicker.Value.Date); cr.SetParameterValue("toDate", toDatePicker.Value.Date); cr.SetParameterValue("todayRate", Common.GetTodayRate()); 

Error

 Invalid Parameter value: exceeds the Min or Max or conflicts with existing value or edit mask 

here, fromDate and toDate have parameters of type Date. TodayRate has a parameter of type "Number".

How to solve this problem?

+4
source share
1 answer

The problem is related to culture-sensitive processing of parameter input from your CR application code. CR seems to be poorly designed when it comes to multilingual support in specific situations, such as that.

The solution, although ugly, is as follows.

For each Date , Time or DateTime parameter field that you have in your report, follow these steps:

  • In the CR designer, change the type of the parameter field to String .
  • Create a new formula field and set its value to one of the following values:

     CDate({?ParamFieldName}) // Date CTime({?ParamFieldName}) // Time CDateTime({?ParamFieldName}) // DateTime 

    depending on the type of source parameter, where ParamFieldName is the name of your parameter field.

  • In the application code, pass the parameter value in one of the following ways:

     // Date report.SetParameterValue( "ParamFieldName", DateTimeObject.ToShortDateString().TrimEnd('.')); // Time report.SetParameterValue( "ParamFieldName", DateTimeObject.ToShortTimeString()); // DateTime report.SetParameterValue( "ParamFieldName", string.Format("{0} {1}", DateTimeObject.ToShortDateString().TrimEnd('.'), DateTimeObject.ToShortTimeString())); 
  • In the CR designer, insert the formula fields instead of the parameter fields and format their display in the CR designer.

This has been tested on several cultures.

The end point in the date string is truncated because CR, for unknown reasons, cannot process the point, even in cultures that have a point at the end of the dates (for example, Serbian - 14.3.2015. )

0
source

Source: https://habr.com/ru/post/1502265/


All Articles