Solved

Date Parameters and C#

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

13 Experts available now in Live!

Get 1:1 Help Now