Solved

Date Parameters and C#

Posted on 2004-03-22
5
1,345 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now