By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,686 Members | 2,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,686 IT Pros & Developers. It's quick & easy.

Settting Stored Procedure Parameters for VS2003 Crystal Reports

P: n/a
I have been fighting through my first crystal report in VS2003.NET and have
made some headway. Here is what I've done:

1. Created a crystal report in VS2003 from a SQL stored procedure with
parameters through the GUI.

2. Finally got past the logon failure error to display the report using the
viewer. I assume that default parameters are being used since it does
display some data and the SP won't run without being passed some values.

No, I have to pass the parameters for the stored procedure. Can someone
tell me what is wrong with the code below? Can I pass these parameters
using the viewer of do I have to use the report document? If I have to use
the report doc how would I change this? I have spent more time on this than
any other problem in my entire career. Any help would be greatly
appreciated!!!

I recieve this error:

Exception Details: System.ArgumentOutOfRangeException: Specified argument
was out of the range of valid values.

Source Error:
Line 57:
Line 58: crParameterFields = CrystalReportViewer1.ParameterFieldInfo;
Line 59: crParameterField = crParameterFields["@startyearpart"];
Line 60: crParameterValues = crParameterField.CurrentValues;
Line 61: crParameterDiscreteValue = new ParameterDiscreteValue();
Here is my code:

using System;
using System.Collections;
using System.ComponentModel;
using CrystalDecisions.CrystalReports.Engine; //added
using CrystalDecisions.Shared; //added
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ptr
{
/// <summary>
/// Summary description for availToActualHoursSP.
/// </summary>
public class availToActualHoursSP : System.Web.UI.Page
{
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;

//Crystal Report Variables
availToActualHoursCR crReportDocument = new availToActualHoursCR();

//'CrystalReport1' must be the name the CrystalReport
TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();

//Crystal Report Properties
CrystalDecisions.CrystalReports.Engine.Database crDatabase;
CrystalDecisions.CrystalReports.Engine.Tables crTables;
CrystalDecisions.CrystalReports.Engine.Table crTable;

ParameterFields crParameterFields;
ParameterField crParameterField;
ParameterValues crParameterValues;
ParameterDiscreteValue crParameterDiscreteValue;

private void Page_Load(object sender, System.EventArgs e)
{
crConnectionInfo.ServerName = "myserver";
crConnectionInfo.DatabaseName = "dbname";
crConnectionInfo.UserID = "sa";
crConnectionInfo.Password = "password";
crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;

foreach(CrystalDecisions.CrystalReports.Engine.Tab le crTable in crTables)
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
}

CrystalReportViewer1.ReportSource = crReportDocument;

//CODE RUNS AND DISPLAYS A REPORT WITHOUT THE PARAMETER CODE BELOW

crParameterFields = CrystalReportViewer1.ParameterFieldInfo;
crParameterField = crParameterFields["@startyearpart"];
crParameterValues = crParameterField.CurrentValues;
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = 2003;
crParameterValues.Add(crParameterDiscreteValue);

crParameterFields = CrystalReportViewer1.ParameterFieldInfo;
crParameterField = crParameterFields["@startmonthpart"];
crParameterValues = crParameterField.CurrentValues;
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = 8;
crParameterValues.Add(crParameterDiscreteValue);
crParameterFields = CrystalReportViewer1.ParameterFieldInfo;
crParameterField = crParameterFields["@endyearpart"];
crParameterValues = crParameterField.CurrentValues;
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = 2004;
crParameterValues.Add(crParameterDiscreteValue);

crParameterFields = CrystalReportViewer1.ParameterFieldInfo;
crParameterField = crParameterFields["@endmonthpart"];
crParameterValues = crParameterField.CurrentValues;
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = 7;
crParameterValues.Add(crParameterDiscreteValue);

crParameterFields = CrystalReportViewer1.ParameterFieldInfo;
crParameterField = crParameterFields["@ccntrs"];
crParameterValues = crParameterField.CurrentValues;
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = "55200,55300";
crParameterValues.Add(crParameterDiscreteValue);

//@startyearpart = 2003
//@startmonthpart = 8
//@endyearpart = 2004
//@endmonthpart = 7
//@ccntrs = '55200,55300'
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.