Solved

Date Parameters and C#

Posted on 2004-03-22
5
1,352 Views
Last Modified: 2007-12-19
Hi

I have this code and it is currently,

for(int i=0;i<oRpt.DataDefinition.ParameterFields.Count; i++)
{
      oRpt.DataDefinition.ParameterFields[i].CurrentValues.Clear();
      switch (oRpt.DataDefinition.ParameterFields[i].ParameterValueKind.ToString())
      {
            case "DateParameter":
            {
                  string sDate = myParam.lstItems[i];
                  DateTime myDate = DateTime.Parse(myParam.lstItems[i]);                                    
                  oRpt.DataDefinition.ParameterFields[i].CurrentValues.Add(myDate.Date);
                  break;
            }
      }
}

My problem is that i get this error:

An unhandled exception of type 'System.ArgumentException' occurred in crystaldecisions.shared.dll

Additional information: Invalid object type.

I am thinking that the DateTime type in C# is not what is being wanted but then i don't have a clue what the type is..

Can anyone help?
0
Comment
Question by:cossy74
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:stasau
ID: 10658667
Crystal is expecting a Parameter Object Type or at least something it can cast as one.  Try:

ParameterValues objParamValues = new ParameterValues();
ParameterDiscreteValue objValue = new ParameterDiscreteValue();

for(int i=0;i<oRpt.DataDefinition.ParameterFields.Count; i++)
{
     oRpt.DataDefinition.ParameterFields[i].CurrentValues.Clear();
     switch (oRpt.DataDefinition.ParameterFields[i].ParameterValueKind.ToString())
     {
          case "DateParameter":
          {
               objValue.Kind = CrystalDecisions.Shared.DiscreteOrRangeKind.DiscreteValue;
               objValue.Value = myParam.lstItems[i];    //  The value you want to pass in  
               objParamValues.Add(objValue);
               oRpt.DataDefinition.ParameterFields[i].CurrentValues.Add(objValue);
               oRpt.DataDefinition.ParameterFields[i].ApplyCurrentValues(objParamValues);
               break;
          }
     }
}
0
 

Author Comment

by:cossy74
ID: 10661693
stasau: The error disappears but the code does not apply the Parameter value because i am getting the parameter input screen after the code is run. Any thoughts?
0
 
LVL 4

Accepted Solution

by:
stasau earned 500 total points
ID: 10661740
Are you setting all of the parameter values?  When the parameter screen pops up it will prompt for all of the parameters you have not set programmically.  Is it asking for all of the parameters, or are some of them set.  You might also want to step through you code and make sure that the parameter code is executing for all the parameters in your report.
0
 

Author Comment

by:cossy74
ID: 10662251
stasau: there is only one parameter in this report and it is the dateParameter.
0
 

Author Comment

by:cossy74
ID: 10700299
Hi,

This is what i have found that works.....

// all the parameter fields will be added to this collection
ParameterFields paramFields = new ParameterFields();

for(int i=0;i<oRpt.DataDefinition.ParameterFields.Count; i++)
{
      // the parameter fields to be sent to the report                         
      ParameterField pfParam = new ParameterField();
      pfParam.ParameterFieldName = oRpt.DataDefinition.ParameterFields[i].Name;

      // the above declared parameter fields accept values as discrete objects
      // so declaring discrete objects
      ParameterDiscreteValue dcParam = new ParameterDiscreteValue();
      
      switch (oRpt.DataDefinition.ParameterFields[i].ParameterValueKind.ToString())
      {
            case "DateParameter":
            {
                  // setting the values of discrete objects
                  dcParam.Value = DateTime.Parse(myParam.lstItems[0]);
                  break;
            }
      }

      // now adding these discrete values to parameters
      pfParam.CurrentValues.Add(dcParam);

      // now adding all these parameter fields to the parameter collection
      paramFields.Add(pfParam);
}

//*********************************************
// finally add the parameter collection to the crystal report viewer
//*********************************************
crv_Viewer.ParameterFieldInfo = paramFields;
//*********************************************

stasau: points are yours for trying to help.....
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question