Solved

Date Parameters and C#

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Crystal reports - finding a hidden reference 4 73
Crystal Reports - group header 2 44
Rounding duration within 20 min intervals 3 39
Crystal report highlighting 5 38
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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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 …

776 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