CrystalReports: Value does not fall within the expected range.

Discussion in 'ASP .Net' started by =?Utf-8?B?amF2YXRvcGlh?=, Oct 5, 2005.

  1. Hello,

    I am trying to show a Crystal Reports 10 Enterprise report in an ASP.NET
    page (C#). I can run the report via the admin console just fine. When I try
    to show the report, after setting up its parameters, I get:

    "Value does not fall within the expected range."

    How are people interacting with the Crystal Report viewer to set the
    parameters on a report? I haven't found any useful documentation at
    BusinessObjects.com or even with the crystal distribution. Following my
    closing of this post is the code I use to setup the report for viewing.

    Thanks

    -- Jake

    [ CODE ]

    // Setup the crystal enterprise logon information
    SessionMgr sm = new SessionMgr();
    EnterpriseSession es = sm.Logon(uname, pwd, cms, auth);
    //
    // Discover the crystal ID of the report to view
    //
    EnterpriseService service = es.GetService("InfoStore");
    InfoStore info = new InfoStore(service);
    string query = "Select * From CI_INFOOBJECTS Where SI_PROGID =
    'CrystalEnterprise.Report' AND SI_ID=" + ReportID + " AND SI_INSTANCE = 0";
    InfoObjects objs = info.Query(query);
    //
    // Setup the report and parameters.
    //
    if(objs.Count > 0)
    {
    // The InfoObjects collection is '1' based, not '0' based.
    Report rpt = (Report)objs[1];
    EnterpriseService es2 = es.GetService("PSReportFactory");
    PSReportFactory ps = (PSReportFactory)es2.Interface;
    ReportSource rs = ps.OpenReportSource(rpt.ID);
    if(Report.HasParameters)
    {
    CrystalReportViewer1.ParameterFieldInfo.Clear();
    ReportParameters pms = rpt.ReportParameters;
    ParameterFields pfs = new ParameterFields();
    foreach(ReportParameter rp in pms)
    {
    ParameterField pf = new ParameterField();
    ParameterDiscreteValue pv = new ParameterDiscreteValue();
    pf.Name = rp.ParameterName;
    // Get the value from the input
    string v = ReportQueryControl1.GetValue(rp.ParameterName);
    switch(rp.ValueType)
    {
    case CeReportVariableValueType.ceRVDateTime:
    try
    {
    DateTime dt = DateTime.ParseExact(v, "MM/dd/yyyy HH:mm:ss",
    CultureInfo.InvariantCulture, DateTimeStyles.None);
    pv.Value = dt; // string.Format("DateTime({0:yyyy,MM,dd,HH,mm,ss})", dt);
    pf.ParameterValueType = ParameterValueKind.DateTimeParameter;
    }
    catch(Exception ex)
    {
    Trace.Write("Invalid date time format: " + v + " (" + ex.Message + ")");
    pv.Value = v;
    }
    break;
    case CeReportVariableValueType.ceRVDate:
    try
    {
    DateTime dt = DateTime.ParseExact(v, "MM/dd/yyyy",
    CultureInfo.InvariantCulture, DateTimeStyles.None);
    pv.Value = dt; // string.Format("Date({0:yyyy,MM,dd})", dt);
    pf.ParameterValueType = ParameterValueKind.DateParameter;
    }
    catch(Exception ex)
    {
    Trace.Write("Invalid date format: " + v + " (" + ex.Message + ")");
    pv.Value = v;
    pf.ParameterValueType = ParameterValueKind.StringParameter;
    }
    break;
    default:
    pv.Value = v;
    pf.ParameterValueType = ParameterValueKind.StringParameter;
    break;
    }
    if(pv.Value == null && !rp.EnableNullValue)
    {
    // Ignore undefined values
    continue;
    }
    Trace.Write("ShowCrystalReport(): Report " + rpt.ID + ", [" +
    rp.ValueType + "," + pf.ParameterValueType + "," + pf.ParameterValueKind + "]
    " + pf.Name + "=" + pv.Value);
    pf.CurrentValues.AddValue(pv);
    CrystalReportViewer1.ParameterFieldInfo.Add(pf);
    }
    }
    CrystalReportViewer1.EnterpriseLogon = es;
    CrystalReportViewer1.ReportSource = rs;
    CrystalReportViewer1.Visible = true;
    =?Utf-8?B?amF2YXRvcGlh?=, Oct 5, 2005
    #1
    1. Advertising

  2. What's even more odd is this stack trace from the error:

    System.ArgumentException: Value does not fall within the expected range.
    at CrystalDecisions.Shared.SharedUtils.ConvertToDecimal(Object value)
    at CrystalDecisions.Shared.ParameterValues.AddValue(Object value)
    at AGIA.EnterpriseReports.ViewReport.ShowCrystalReport() in
    j:\cvsroot\clients\arrowhead\enterprisereporting\www\viewreport.aspx.cs:line
    381

    The report is configured for a Date property (StartBookDate).

    -- Jake


    "javatopia" wrote:

    > Hello,
    >
    > I am trying to show a Crystal Reports 10 Enterprise report in an ASP.NET
    > page (C#). I can run the report via the admin console just fine. When I try
    > to show the report, after setting up its parameters, I get:
    >
    > "Value does not fall within the expected range."
    >
    > How are people interacting with the Crystal Report viewer to set the
    > parameters on a report? I haven't found any useful documentation at
    > BusinessObjects.com or even with the crystal distribution. Following my
    > closing of this post is the code I use to setup the report for viewing.
    >
    > Thanks
    >
    > -- Jake
    >
    > [ CODE ]
    >
    > // Setup the crystal enterprise logon information
    > SessionMgr sm = new SessionMgr();
    > EnterpriseSession es = sm.Logon(uname, pwd, cms, auth);
    > //
    > // Discover the crystal ID of the report to view
    > //
    > EnterpriseService service = es.GetService("InfoStore");
    > InfoStore info = new InfoStore(service);
    > string query = "Select * From CI_INFOOBJECTS Where SI_PROGID =
    > 'CrystalEnterprise.Report' AND SI_ID=" + ReportID + " AND SI_INSTANCE = 0";
    > InfoObjects objs = info.Query(query);
    > //
    > // Setup the report and parameters.
    > //
    > if(objs.Count > 0)
    > {
    > // The InfoObjects collection is '1' based, not '0' based.
    > Report rpt = (Report)objs[1];
    > EnterpriseService es2 = es.GetService("PSReportFactory");
    > PSReportFactory ps = (PSReportFactory)es2.Interface;
    > ReportSource rs = ps.OpenReportSource(rpt.ID);
    > if(Report.HasParameters)
    > {
    > CrystalReportViewer1.ParameterFieldInfo.Clear();
    > ReportParameters pms = rpt.ReportParameters;
    > ParameterFields pfs = new ParameterFields();
    > foreach(ReportParameter rp in pms)
    > {
    > ParameterField pf = new ParameterField();
    > ParameterDiscreteValue pv = new ParameterDiscreteValue();
    > pf.Name = rp.ParameterName;
    > // Get the value from the input
    > string v = ReportQueryControl1.GetValue(rp.ParameterName);
    > switch(rp.ValueType)
    > {
    > case CeReportVariableValueType.ceRVDateTime:
    > try
    > {
    > DateTime dt = DateTime.ParseExact(v, "MM/dd/yyyy HH:mm:ss",
    > CultureInfo.InvariantCulture, DateTimeStyles.None);
    > pv.Value = dt; // string.Format("DateTime({0:yyyy,MM,dd,HH,mm,ss})", dt);
    > pf.ParameterValueType = ParameterValueKind.DateTimeParameter;
    > }
    > catch(Exception ex)
    > {
    > Trace.Write("Invalid date time format: " + v + " (" + ex.Message + ")");
    > pv.Value = v;
    > }
    > break;
    > case CeReportVariableValueType.ceRVDate:
    > try
    > {
    > DateTime dt = DateTime.ParseExact(v, "MM/dd/yyyy",
    > CultureInfo.InvariantCulture, DateTimeStyles.None);
    > pv.Value = dt; // string.Format("Date({0:yyyy,MM,dd})", dt);
    > pf.ParameterValueType = ParameterValueKind.DateParameter;
    > }
    > catch(Exception ex)
    > {
    > Trace.Write("Invalid date format: " + v + " (" + ex.Message + ")");
    > pv.Value = v;
    > pf.ParameterValueType = ParameterValueKind.StringParameter;
    > }
    > break;
    > default:
    > pv.Value = v;
    > pf.ParameterValueType = ParameterValueKind.StringParameter;
    > break;
    > }
    > if(pv.Value == null && !rp.EnableNullValue)
    > {
    > // Ignore undefined values
    > continue;
    > }
    > Trace.Write("ShowCrystalReport(): Report " + rpt.ID + ", [" +
    > rp.ValueType + "," + pf.ParameterValueType + "," + pf.ParameterValueKind + "]
    > " + pf.Name + "=" + pv.Value);
    > pf.CurrentValues.AddValue(pv);
    > CrystalReportViewer1.ParameterFieldInfo.Add(pf);
    > }
    > }
    > CrystalReportViewer1.EnterpriseLogon = es;
    > CrystalReportViewer1.ReportSource = rs;
    > CrystalReportViewer1.Visible = true;
    >
    =?Utf-8?B?amF2YXRvcGlh?=, Oct 5, 2005
    #2
    1. Advertising

  3. Try following code to assign parameter to CR report:

    ParameterDiscreteValue discretevalue = new ParameterDiscreteValue();
    discretevalue.Value = objValue; // Assign parameter
    ParameterValues values = new ParameterValues();
    values.Add(discretevalue);
    crReport.DataDefinition.ParameterFields.ApplyCurrentValues(values);

    HTH

    Elton Wang

    "javatopia" wrote:

    > What's even more odd is this stack trace from the error:
    >
    > System.ArgumentException: Value does not fall within the expected range.
    > at CrystalDecisions.Shared.SharedUtils.ConvertToDecimal(Object value)
    > at CrystalDecisions.Shared.ParameterValues.AddValue(Object value)
    > at AGIA.EnterpriseReports.ViewReport.ShowCrystalReport() in
    > j:\cvsroot\clients\arrowhead\enterprisereporting\www\viewreport.aspx.cs:line
    > 381
    >
    > The report is configured for a Date property (StartBookDate).
    >
    > -- Jake
    >
    >
    > "javatopia" wrote:
    >
    > > Hello,
    > >
    > > I am trying to show a Crystal Reports 10 Enterprise report in an ASP.NET
    > > page (C#). I can run the report via the admin console just fine. When I try
    > > to show the report, after setting up its parameters, I get:
    > >
    > > "Value does not fall within the expected range."
    > >
    > > How are people interacting with the Crystal Report viewer to set the
    > > parameters on a report? I haven't found any useful documentation at
    > > BusinessObjects.com or even with the crystal distribution. Following my
    > > closing of this post is the code I use to setup the report for viewing.
    > >
    > > Thanks
    > >
    > > -- Jake
    > >
    > > [ CODE ]
    > >
    > > // Setup the crystal enterprise logon information
    > > SessionMgr sm = new SessionMgr();
    > > EnterpriseSession es = sm.Logon(uname, pwd, cms, auth);
    > > //
    > > // Discover the crystal ID of the report to view
    > > //
    > > EnterpriseService service = es.GetService("InfoStore");
    > > InfoStore info = new InfoStore(service);
    > > string query = "Select * From CI_INFOOBJECTS Where SI_PROGID =
    > > 'CrystalEnterprise.Report' AND SI_ID=" + ReportID + " AND SI_INSTANCE = 0";
    > > InfoObjects objs = info.Query(query);
    > > //
    > > // Setup the report and parameters.
    > > //
    > > if(objs.Count > 0)
    > > {
    > > // The InfoObjects collection is '1' based, not '0' based.
    > > Report rpt = (Report)objs[1];
    > > EnterpriseService es2 = es.GetService("PSReportFactory");
    > > PSReportFactory ps = (PSReportFactory)es2.Interface;
    > > ReportSource rs = ps.OpenReportSource(rpt.ID);
    > > if(Report.HasParameters)
    > > {
    > > CrystalReportViewer1.ParameterFieldInfo.Clear();
    > > ReportParameters pms = rpt.ReportParameters;
    > > ParameterFields pfs = new ParameterFields();
    > > foreach(ReportParameter rp in pms)
    > > {
    > > ParameterField pf = new ParameterField();
    > > ParameterDiscreteValue pv = new ParameterDiscreteValue();
    > > pf.Name = rp.ParameterName;
    > > // Get the value from the input
    > > string v = ReportQueryControl1.GetValue(rp.ParameterName);
    > > switch(rp.ValueType)
    > > {
    > > case CeReportVariableValueType.ceRVDateTime:
    > > try
    > > {
    > > DateTime dt = DateTime.ParseExact(v, "MM/dd/yyyy HH:mm:ss",
    > > CultureInfo.InvariantCulture, DateTimeStyles.None);
    > > pv.Value = dt; // string.Format("DateTime({0:yyyy,MM,dd,HH,mm,ss})", dt);
    > > pf.ParameterValueType = ParameterValueKind.DateTimeParameter;
    > > }
    > > catch(Exception ex)
    > > {
    > > Trace.Write("Invalid date time format: " + v + " (" + ex.Message + ")");
    > > pv.Value = v;
    > > }
    > > break;
    > > case CeReportVariableValueType.ceRVDate:
    > > try
    > > {
    > > DateTime dt = DateTime.ParseExact(v, "MM/dd/yyyy",
    > > CultureInfo.InvariantCulture, DateTimeStyles.None);
    > > pv.Value = dt; // string.Format("Date({0:yyyy,MM,dd})", dt);
    > > pf.ParameterValueType = ParameterValueKind.DateParameter;
    > > }
    > > catch(Exception ex)
    > > {
    > > Trace.Write("Invalid date format: " + v + " (" + ex.Message + ")");
    > > pv.Value = v;
    > > pf.ParameterValueType = ParameterValueKind.StringParameter;
    > > }
    > > break;
    > > default:
    > > pv.Value = v;
    > > pf.ParameterValueType = ParameterValueKind.StringParameter;
    > > break;
    > > }
    > > if(pv.Value == null && !rp.EnableNullValue)
    > > {
    > > // Ignore undefined values
    > > continue;
    > > }
    > > Trace.Write("ShowCrystalReport(): Report " + rpt.ID + ", [" +
    > > rp.ValueType + "," + pf.ParameterValueType + "," + pf.ParameterValueKind + "]
    > > " + pf.Name + "=" + pv.Value);
    > > pf.CurrentValues.AddValue(pv);
    > > CrystalReportViewer1.ParameterFieldInfo.Add(pf);
    > > }
    > > }
    > > CrystalReportViewer1.EnterpriseLogon = es;
    > > CrystalReportViewer1.ReportSource = rs;
    > > CrystalReportViewer1.Visible = true;
    > >
    =?Utf-8?B?RWx0b24gVw==?=, Oct 6, 2005
    #3
  4. I do not see any methods that are "DataDefinition" or
    ParameterField.ApplyCurrentValues. You might be referring to a version of
    Crystal that is not mine? I am using Crystal Enterprise version 10, not CR9
    for VS.NET.

    The stack trace I posted shows that the values are being applied to the
    crystal report visa vie the report viewer's ParameterFieldInfo attribute.

    CrystalDecisions.Enterprise.Desktop.Report is the report class I use

    CrystalDecisions.Web.CrystalReportViewer is the viewer I use

    CrystalDecisions.Web.dll v 10.0.3300.0 is my version

    -- Jake


    "Elton W" wrote:

    > Try following code to assign parameter to CR report:
    >
    > ParameterDiscreteValue discretevalue = new ParameterDiscreteValue();
    > discretevalue.Value = objValue; // Assign parameter
    > ParameterValues values = new ParameterValues();
    > values.Add(discretevalue);
    > crReport.DataDefinition.ParameterFields.ApplyCurrentValues(values);
    >
    > HTH
    >
    > Elton Wang
    >
    > "javatopia" wrote:
    >
    > > What's even more odd is this stack trace from the error:
    > >
    > > System.ArgumentException: Value does not fall within the expected range.
    > > at CrystalDecisions.Shared.SharedUtils.ConvertToDecimal(Object value)
    > > at CrystalDecisions.Shared.ParameterValues.AddValue(Object value)
    > > at AGIA.EnterpriseReports.ViewReport.ShowCrystalReport() in
    > > j:\cvsroot\clients\arrowhead\enterprisereporting\www\viewreport.aspx.cs:line
    > > 381
    > >
    > > The report is configured for a Date property (StartBookDate).
    > >
    > > -- Jake
    > >
    > >
    > > "javatopia" wrote:
    > >
    > > > Hello,
    > > >
    > > > I am trying to show a Crystal Reports 10 Enterprise report in an ASP.NET
    > > > page (C#). I can run the report via the admin console just fine. When I try
    > > > to show the report, after setting up its parameters, I get:
    > > >
    > > > "Value does not fall within the expected range."
    > > >
    > > > How are people interacting with the Crystal Report viewer to set the
    > > > parameters on a report? I haven't found any useful documentation at
    > > > BusinessObjects.com or even with the crystal distribution. Following my
    > > > closing of this post is the code I use to setup the report for viewing.
    > > >
    > > > Thanks
    > > >
    > > > -- Jake
    > > >
    > > > [ CODE ]
    > > >
    > > > // Setup the crystal enterprise logon information
    > > > SessionMgr sm = new SessionMgr();
    > > > EnterpriseSession es = sm.Logon(uname, pwd, cms, auth);
    > > > //
    > > > // Discover the crystal ID of the report to view
    > > > //
    > > > EnterpriseService service = es.GetService("InfoStore");
    > > > InfoStore info = new InfoStore(service);
    > > > string query = "Select * From CI_INFOOBJECTS Where SI_PROGID =
    > > > 'CrystalEnterprise.Report' AND SI_ID=" + ReportID + " AND SI_INSTANCE = 0";
    > > > InfoObjects objs = info.Query(query);
    > > > //
    > > > // Setup the report and parameters.
    > > > //
    > > > if(objs.Count > 0)
    > > > {
    > > > // The InfoObjects collection is '1' based, not '0' based.
    > > > Report rpt = (Report)objs[1];
    > > > EnterpriseService es2 = es.GetService("PSReportFactory");
    > > > PSReportFactory ps = (PSReportFactory)es2.Interface;
    > > > ReportSource rs = ps.OpenReportSource(rpt.ID);
    > > > if(Report.HasParameters)
    > > > {
    > > > CrystalReportViewer1.ParameterFieldInfo.Clear();
    > > > ReportParameters pms = rpt.ReportParameters;
    > > > ParameterFields pfs = new ParameterFields();
    > > > foreach(ReportParameter rp in pms)
    > > > {
    > > > ParameterField pf = new ParameterField();
    > > > ParameterDiscreteValue pv = new ParameterDiscreteValue();
    > > > pf.Name = rp.ParameterName;
    > > > // Get the value from the input
    > > > string v = ReportQueryControl1.GetValue(rp.ParameterName);
    > > > switch(rp.ValueType)
    > > > {
    > > > case CeReportVariableValueType.ceRVDateTime:
    > > > try
    > > > {
    > > > DateTime dt = DateTime.ParseExact(v, "MM/dd/yyyy HH:mm:ss",
    > > > CultureInfo.InvariantCulture, DateTimeStyles.None);
    > > > pv.Value = dt; // string.Format("DateTime({0:yyyy,MM,dd,HH,mm,ss})", dt);
    > > > pf.ParameterValueType = ParameterValueKind.DateTimeParameter;
    > > > }
    > > > catch(Exception ex)
    > > > {
    > > > Trace.Write("Invalid date time format: " + v + " (" + ex.Message + ")");
    > > > pv.Value = v;
    > > > }
    > > > break;
    > > > case CeReportVariableValueType.ceRVDate:
    > > > try
    > > > {
    > > > DateTime dt = DateTime.ParseExact(v, "MM/dd/yyyy",
    > > > CultureInfo.InvariantCulture, DateTimeStyles.None);
    > > > pv.Value = dt; // string.Format("Date({0:yyyy,MM,dd})", dt);
    > > > pf.ParameterValueType = ParameterValueKind.DateParameter;
    > > > }
    > > > catch(Exception ex)
    > > > {
    > > > Trace.Write("Invalid date format: " + v + " (" + ex.Message + ")");
    > > > pv.Value = v;
    > > > pf.ParameterValueType = ParameterValueKind.StringParameter;
    > > > }
    > > > break;
    > > > default:
    > > > pv.Value = v;
    > > > pf.ParameterValueType = ParameterValueKind.StringParameter;
    > > > break;
    > > > }
    > > > if(pv.Value == null && !rp.EnableNullValue)
    > > > {
    > > > // Ignore undefined values
    > > > continue;
    > > > }
    > > > Trace.Write("ShowCrystalReport(): Report " + rpt.ID + ", [" +
    > > > rp.ValueType + "," + pf.ParameterValueType + "," + pf.ParameterValueKind + "]
    > > > " + pf.Name + "=" + pv.Value);
    > > > pf.CurrentValues.AddValue(pv);
    > > > CrystalReportViewer1.ParameterFieldInfo.Add(pf);
    > > > }
    > > > }
    > > > CrystalReportViewer1.EnterpriseLogon = es;
    > > > CrystalReportViewer1.ReportSource = rs;
    > > > CrystalReportViewer1.Visible = true;
    > > >
    =?Utf-8?B?amF2YXRvcGlh?=, Oct 6, 2005
    #4
  5. Found a solution:

    // Create the document
    CrystalDecisions.CrystalReports.Engine.ReportDocument myReportDocument;

    myReportDocument = new
    CrystalDecisions.CrystalReports.Engine.ReportDocument();
    myReportDocument.EnterpriseLogonInfo.AuthenticationType = auth;
    myReportDocument.EnterpriseLogonInfo.CmsServer = cms;
    myReportDocument.EnterpriseLogonInfo.Username =
    uname; myReportDocument.EnterpriseLogonInfo.Password = pwd;
    myReportDocument.FileName = "ceis://@" + cms + "/#" + ReportID;
    myReportDocument.UriIsUserEditable = false;

    // Set the logon
    [Can only set the logon at this point, after the file name is set]

    TableLogOnInfo logon = new TableLogOnInfo();
    ConnectionInfo ci = new ConnectionInfo();

    myReportDocument.SetDatabaseLogon(ci.UserID, ci.Password, ci.ServerName,
    ci.DatabaseName);

    CrystalReportViewer1.LogOnInfo.Add(CrystalLogonInfo);

    // Set the parameters. I cache the parameter values in a hashtable
    // and put that into the session for later use in the Init handler of the
    // crystal viewer

    foreach(string key in hashParams.Keys)
    {
    myReportDocument.SetParameterValue(key, hashParams[key]);
    }

    // Make the report visible

    CrystalReportViewer1.ReportSource = myReportDocument;
    CrystalReportViewer1.Visible = true;

    That did it. To handle postback events from the report viewer, I had to add
    an init handler on the report viewer and cache all of the report and logon
    params to set them on the viewer in the init handler.

    This is also the same sample that is shown in the Using Crystal Reports 10
    by Neil Fitzgerald, et. al., via QUE Publishing.

    -- Jake
    =?Utf-8?B?amF2YXRvcGlh?=, Oct 14, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    15
    Views:
    588
    Mark Parnell
    Nov 25, 2003
  2. anamika
    Replies:
    0
    Views:
    950
    anamika
    Jun 15, 2006
  3. Jack Dowson
    Replies:
    4
    Views:
    378
    Roman
    May 6, 2007
  4. Tomoyuki Kosimizu

    Range does not take an Range object.

    Tomoyuki Kosimizu, Nov 25, 2003, in forum: Ruby
    Replies:
    3
    Views:
    151
    Tomoyuki Kosimizu
    Nov 27, 2003
  5. David Bird
    Replies:
    1
    Views:
    209
    Tiago Macedo
    Jun 23, 2008
Loading...

Share This Page