Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal parameter in formula fails in VS2005. Help

Status
Not open for further replies.

mjjks

Programmer
Jun 22, 2005
138
US


Hi All.
I have a report developed in Crystal XI. It has stored procedure as data source, which takes two parameters (@StarDate and @EndDate). I use those data parameters in formulas and everything works great, when I run report in Crystal.

I added report to VS2005 project and when I try to run it, I get an error: "This field name is not known" and tells formula name. If I comment content of that formula, it moves to next with the same error.

I need some help with this as it holds me from deploying my project. Any ideas what might cause this error?
Thanks for your help.

Code I'm using to open report:
Code:
 Critical_Stations oRpt = new Critical_Stations();
          
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand("exec usp_RPT_CRIT_STATIONS '" + StartDate + "','" + EndDate + "'", this.GetConnection("HTCIS"));
            DataTable dt = new DataTable("CS");
            da.Fill(dt);
           
            /* Start date */
            ParameterField pfBeginDate = new ParameterField();
            ParameterDiscreteValue pvBeginDate = new ParameterDiscreteValue();
            pfBeginDate.ParameterFieldName = "@STARTDATE";
            pvBeginDate.Value = StartDate;
            pfBeginDate.CurrentValues.Add(pvBeginDate);

            /* End Date */
            ParameterField pfEndDate = new ParameterField();
            ParameterDiscreteValue pvEndDate = new ParameterDiscreteValue();
            pfEndDate.ParameterFieldName = "@ENDDATE";
            pvEndDate.Value = EndDate;
            pfEndDate.CurrentValues.Add(pvEndDate);

            /* Add parameters  to viewer */
            ParameterFields pFields = new ParameterFields();
            pFields.Add(pfBeginDate);
            pFields.Add(pfEndDate);
            crw.ParameterFieldInfo = pFields;
  
            /* Set report source and open it */
            oRpt.SetDataSource(dt.DefaultView);
            crw.ReportSource = oRpt;

This is one of the formulas I use in Crystal, named "FormatStartDTTM" that causes an error:
Code:
Date({?@STARTDATE});



 
you don't want to pass the parameters to the viewer. Rather set the parameters in the reportsource.
Code:
myReportSource.SetParamter("STARTDATE", pvBeginDate);
myReportSource.SetParamter("ENDDATE", pvEndDate);

all the viewer does is display the information, it doesn't know anything about which report or what the arguements are. that's the reportsource's responsibility.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 

Jason,
Thanks for the reply.
How do you set report's source parameter?
[highlight]myReportSource[/highlight].SetParamter("STARTDATE", pvBeginDate);
I tried to set parameter for report object like below but still get an error.

Code:
oRpt.SetParameterValue("@STARTDATE", StartDate)

Interestingly enough, if I modify any working report that uses stored procedure, to use parameter in a formula, it starts to fail in similar manner.

Parameter itself on report doesn't cause crash, but won't display either. Everything runs just fine if I run Crystal by itself. Go figure.
 
try this instead:
Code:
myReportSource.ReportDocument.SetParamter("STARTDATE", pvBeginDate);
myReportSource.ReportDocument.SetParamter("ENDDATE", pvEndDate);
this assumes the report file is already loaded. if the report isn't loaded yet, then I think an excpetion is thrown.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top