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.Argument OutOfRangeExcep tion: Specified argument
was out of the range of valid values.
Source Error:
Line 57:
Line 58: crParameterFiel ds = CrystalReportVi ewer1.Parameter FieldInfo;
Line 59: crParameterFiel d = crParameterFiel ds["@startyearpart "];
Line 60: crParameterValu es = crParameterFiel d.CurrentValues ;
Line 61: crParameterDisc reteValue = new ParameterDiscre teValue();
Here is my code:
using System;
using System.Collecti ons;
using System.Componen tModel;
using CrystalDecision s.CrystalReport s.Engine; //added
using CrystalDecision s.Shared; //added
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
namespace ptr
{
/// <summary>
/// Summary description for availToActualHo ursSP.
/// </summary>
public class availToActualHo ursSP : System.Web.UI.P age
{
protected CrystalDecision s.Web.CrystalRe portViewer CrystalReportVi ewer1;
//Crystal Report Variables
availToActualHo ursCR crReportDocumen t = new availToActualHo ursCR();
//'CrystalReport1 ' must be the name the CrystalReport
TableLogOnInfo crTableLogOnInf o = new TableLogOnInfo( );
ConnectionInfo crConnectionInf o = new ConnectionInfo( );
//Crystal Report Properties
CrystalDecision s.CrystalReport s.Engine.Databa se crDatabase;
CrystalDecision s.CrystalReport s.Engine.Tables crTables;
CrystalDecision s.CrystalReport s.Engine.Table crTable;
ParameterFields crParameterFiel ds;
ParameterField crParameterFiel d;
ParameterValues crParameterValu es;
ParameterDiscre teValue crParameterDisc reteValue;
private void Page_Load(objec t sender, System.EventArg s e)
{
crConnectionInf o.ServerName = "myserver";
crConnectionInf o.DatabaseName = "dbname";
crConnectionInf o.UserID = "sa";
crConnectionInf o.Password = "password";
crDatabase = crReportDocumen t.Database;
crTables = crDatabase.Tabl es;
foreach(Crystal Decisions.Cryst alReports.Engin e.Table crTable in crTables)
{
crTableLogOnInf o = crTable.LogOnIn fo;
crTableLogOnInf o.ConnectionInf o = crConnectionInf o;
crTable.ApplyLo gOnInfo(crTable LogOnInfo);
}
CrystalReportVi ewer1.ReportSou rce = crReportDocumen t;
//CODE RUNS AND DISPLAYS A REPORT WITHOUT THE PARAMETER CODE BELOW
crParameterFiel ds = CrystalReportVi ewer1.Parameter FieldInfo;
crParameterFiel d = crParameterFiel ds["@startyearpart "];
crParameterValu es = crParameterFiel d.CurrentValues ;
crParameterDisc reteValue = new ParameterDiscre teValue();
crParameterDisc reteValue.Value = 2003;
crParameterValu es.Add(crParame terDiscreteValu e);
crParameterFiel ds = CrystalReportVi ewer1.Parameter FieldInfo;
crParameterFiel d = crParameterFiel ds["@startmonthpar t"];
crParameterValu es = crParameterFiel d.CurrentValues ;
crParameterDisc reteValue = new ParameterDiscre teValue();
crParameterDisc reteValue.Value = 8;
crParameterValu es.Add(crParame terDiscreteValu e);
crParameterFiel ds = CrystalReportVi ewer1.Parameter FieldInfo;
crParameterFiel d = crParameterFiel ds["@endyearpa rt"];
crParameterValu es = crParameterFiel d.CurrentValues ;
crParameterDisc reteValue = new ParameterDiscre teValue();
crParameterDisc reteValue.Value = 2004;
crParameterValu es.Add(crParame terDiscreteValu e);
crParameterFiel ds = CrystalReportVi ewer1.Parameter FieldInfo;
crParameterFiel d = crParameterFiel ds["@endmonthp art"];
crParameterValu es = crParameterFiel d.CurrentValues ;
crParameterDisc reteValue = new ParameterDiscre teValue();
crParameterDisc reteValue.Value = 7;
crParameterValu es.Add(crParame terDiscreteValu e);
crParameterFiel ds = CrystalReportVi ewer1.Parameter FieldInfo;
crParameterFiel d = crParameterFiel ds["@ccntrs"];
crParameterValu es = crParameterFiel d.CurrentValues ;
crParameterDisc reteValue = new ParameterDiscre teValue();
crParameterDisc reteValue.Value = "55200,5530 0";
crParameterValu es.Add(crParame terDiscreteValu e);
//@startyearpart = 2003
//@startmonthpart = 8
//@endyearpart = 2004
//@endmonthpart = 7
//@ccntrs = '55200,55300'
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
}
#endregion
}
}