Solved

Date Parameters and C#

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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