CrystalReports: Value does not fall within the expected range.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • javatopia

    CrystalReports: Value does not fall within the expected range.

    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();
    EnterpriseSessi on es = sm.Logon(uname, pwd, cms, auth);
    //
    // Discover the crystal ID of the report to view
    //
    EnterpriseServi ce service = es.GetService(" InfoStore");
    InfoStore info = new InfoStore(servi ce);
    string query = "Select * From CI_INFOOBJECTS Where SI_PROGID =
    'CrystalEnterpr ise.Report' AND SI_ID=" + ReportID + " AND SI_INSTANCE = 0";
    InfoObjects objs = info.Query(quer y);
    //
    // Setup the report and parameters.
    //
    if(objs.Count > 0)
    {
    // The InfoObjects collection is '1' based, not '0' based.
    Report rpt = (Report)objs[1];
    EnterpriseServi ce es2 = es.GetService(" PSReportFactory ");
    PSReportFactory ps = (PSReportFactor y)es2.Interface ;
    ReportSource rs = ps.OpenReportSo urce(rpt.ID);
    if(Report.HasPa rameters)
    {
    CrystalReportVi ewer1.Parameter FieldInfo.Clear ();
    ReportParameter s pms = rpt.ReportParam eters;
    ParameterFields pfs = new ParameterFields ();
    foreach(ReportP arameter rp in pms)
    {
    ParameterField pf = new ParameterField( );
    ParameterDiscre teValue pv = new ParameterDiscre teValue();
    pf.Name = rp.ParameterNam e;
    // Get the value from the input
    string v = ReportQueryCont rol1.GetValue(r p.ParameterName );
    switch(rp.Value Type)
    {
    case CeReportVariabl eValueType.ceRV DateTime:
    try
    {
    DateTime dt = DateTime.ParseE xact(v, "MM/dd/yyyy HH:mm:ss",
    CultureInfo.Inv ariantCulture, DateTimeStyles. None);
    pv.Value = dt; // string.Format(" DateTime({0:yyy y,MM,dd,HH,mm,s s})", dt);
    pf.ParameterVal ueType = ParameterValueK ind.DateTimePar ameter;
    }
    catch(Exception ex)
    {
    Trace.Write("In valid date time format: " + v + " (" + ex.Message + ")");
    pv.Value = v;
    }
    break;
    case CeReportVariabl eValueType.ceRV Date:
    try
    {
    DateTime dt = DateTime.ParseE xact(v, "MM/dd/yyyy",
    CultureInfo.Inv ariantCulture, DateTimeStyles. None);
    pv.Value = dt; // string.Format(" Date({0:yyyy,MM ,dd})", dt);
    pf.ParameterVal ueType = ParameterValueK ind.DateParamet er;
    }
    catch(Exception ex)
    {
    Trace.Write("In valid date format: " + v + " (" + ex.Message + ")");
    pv.Value = v;
    pf.ParameterVal ueType = ParameterValueK ind.StringParam eter;
    }
    break;
    default:
    pv.Value = v;
    pf.ParameterVal ueType = ParameterValueK ind.StringParam eter;
    break;
    }
    if(pv.Value == null && !rp.EnableNullV alue)
    {
    // Ignore undefined values
    continue;
    }
    Trace.Write("Sh owCrystalReport (): Report " + rpt.ID + ", [" +
    rp.ValueType + "," + pf.ParameterVal ueType + "," + pf.ParameterVal ueKind + "]
    " + pf.Name + "=" + pv.Value);
    pf.CurrentValue s.AddValue(pv);
    CrystalReportVi ewer1.Parameter FieldInfo.Add(p f);
    }
    }
    CrystalReportVi ewer1.Enterpris eLogon = es;
    CrystalReportVi ewer1.ReportSou rce = rs;
    CrystalReportVi ewer1.Visible = true;

  • javatopia

    #2
    RE: CrystalReports: Value does not fall within the expected range.

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

    System.Argument Exception: Value does not fall within the expected range.
    at CrystalDecision s.Shared.Shared Utils.ConvertTo Decimal(Object value)
    at CrystalDecision s.Shared.Parame terValues.AddVa lue(Object value)
    at AGIA.Enterprise Reports.ViewRep ort.ShowCrystal Report() in
    j:\cvsroot\clie nts\arrowhead\e nterprisereport ing\www\viewrep ort.aspx.cs:lin e
    381

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

    -- Jake


    "javatopia" wrote:
    [color=blue]
    > 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();
    > EnterpriseSessi on es = sm.Logon(uname, pwd, cms, auth);
    > //
    > // Discover the crystal ID of the report to view
    > //
    > EnterpriseServi ce service = es.GetService(" InfoStore");
    > InfoStore info = new InfoStore(servi ce);
    > string query = "Select * From CI_INFOOBJECTS Where SI_PROGID =
    > 'CrystalEnterpr ise.Report' AND SI_ID=" + ReportID + " AND SI_INSTANCE = 0";
    > InfoObjects objs = info.Query(quer y);
    > //
    > // Setup the report and parameters.
    > //
    > if(objs.Count > 0)
    > {
    > // The InfoObjects collection is '1' based, not '0' based.
    > Report rpt = (Report)objs[1];
    > EnterpriseServi ce es2 = es.GetService(" PSReportFactory ");
    > PSReportFactory ps = (PSReportFactor y)es2.Interface ;
    > ReportSource rs = ps.OpenReportSo urce(rpt.ID);
    > if(Report.HasPa rameters)
    > {
    > CrystalReportVi ewer1.Parameter FieldInfo.Clear ();
    > ReportParameter s pms = rpt.ReportParam eters;
    > ParameterFields pfs = new ParameterFields ();
    > foreach(ReportP arameter rp in pms)
    > {
    > ParameterField pf = new ParameterField( );
    > ParameterDiscre teValue pv = new ParameterDiscre teValue();
    > pf.Name = rp.ParameterNam e;
    > // Get the value from the input
    > string v = ReportQueryCont rol1.GetValue(r p.ParameterName );
    > switch(rp.Value Type)
    > {
    > case CeReportVariabl eValueType.ceRV DateTime:
    > try
    > {
    > DateTime dt = DateTime.ParseE xact(v, "MM/dd/yyyy HH:mm:ss",
    > CultureInfo.Inv ariantCulture, DateTimeStyles. None);
    > pv.Value = dt; // string.Format(" DateTime({0:yyy y,MM,dd,HH,mm,s s})", dt);
    > pf.ParameterVal ueType = ParameterValueK ind.DateTimePar ameter;
    > }
    > catch(Exception ex)
    > {
    > Trace.Write("In valid date time format: " + v + " (" + ex.Message + ")");
    > pv.Value = v;
    > }
    > break;
    > case CeReportVariabl eValueType.ceRV Date:
    > try
    > {
    > DateTime dt = DateTime.ParseE xact(v, "MM/dd/yyyy",
    > CultureInfo.Inv ariantCulture, DateTimeStyles. None);
    > pv.Value = dt; // string.Format(" Date({0:yyyy,MM ,dd})", dt);
    > pf.ParameterVal ueType = ParameterValueK ind.DateParamet er;
    > }
    > catch(Exception ex)
    > {
    > Trace.Write("In valid date format: " + v + " (" + ex.Message + ")");
    > pv.Value = v;
    > pf.ParameterVal ueType = ParameterValueK ind.StringParam eter;
    > }
    > break;
    > default:
    > pv.Value = v;
    > pf.ParameterVal ueType = ParameterValueK ind.StringParam eter;
    > break;
    > }
    > if(pv.Value == null && !rp.EnableNullV alue)
    > {
    > // Ignore undefined values
    > continue;
    > }
    > Trace.Write("Sh owCrystalReport (): Report " + rpt.ID + ", [" +
    > rp.ValueType + "," + pf.ParameterVal ueType + "," + pf.ParameterVal ueKind + "]
    > " + pf.Name + "=" + pv.Value);
    > pf.CurrentValue s.AddValue(pv);
    > CrystalReportVi ewer1.Parameter FieldInfo.Add(p f);
    > }
    > }
    > CrystalReportVi ewer1.Enterpris eLogon = es;
    > CrystalReportVi ewer1.ReportSou rce = rs;
    > CrystalReportVi ewer1.Visible = true;
    >[/color]

    Comment

    • Elton W

      #3
      RE: CrystalReports: Value does not fall within the expected range.

      Try following code to assign parameter to CR report:

      ParameterDiscre teValue discretevalue = new ParameterDiscre teValue();
      discretevalue.V alue = objValue; // Assign parameter
      ParameterValues values = new ParameterValues ();
      values.Add(disc retevalue);
      crReport.DataDe finition.Parame terFields[i].ApplyCurrentVa lues(values);

      HTH

      Elton Wang

      "javatopia" wrote:
      [color=blue]
      > What's even more odd is this stack trace from the error:
      >
      > System.Argument Exception: Value does not fall within the expected range.
      > at CrystalDecision s.Shared.Shared Utils.ConvertTo Decimal(Object value)
      > at CrystalDecision s.Shared.Parame terValues.AddVa lue(Object value)
      > at AGIA.Enterprise Reports.ViewRep ort.ShowCrystal Report() in
      > j:\cvsroot\clie nts\arrowhead\e nterprisereport ing\www\viewrep ort.aspx.cs:lin e
      > 381
      >
      > The report is configured for a Date property (StartBookDate) .
      >
      > -- Jake
      >
      >
      > "javatopia" wrote:
      >[color=green]
      > > 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();
      > > EnterpriseSessi on es = sm.Logon(uname, pwd, cms, auth);
      > > //
      > > // Discover the crystal ID of the report to view
      > > //
      > > EnterpriseServi ce service = es.GetService(" InfoStore");
      > > InfoStore info = new InfoStore(servi ce);
      > > string query = "Select * From CI_INFOOBJECTS Where SI_PROGID =
      > > 'CrystalEnterpr ise.Report' AND SI_ID=" + ReportID + " AND SI_INSTANCE = 0";
      > > InfoObjects objs = info.Query(quer y);
      > > //
      > > // Setup the report and parameters.
      > > //
      > > if(objs.Count > 0)
      > > {
      > > // The InfoObjects collection is '1' based, not '0' based.
      > > Report rpt = (Report)objs[1];
      > > EnterpriseServi ce es2 = es.GetService(" PSReportFactory ");
      > > PSReportFactory ps = (PSReportFactor y)es2.Interface ;
      > > ReportSource rs = ps.OpenReportSo urce(rpt.ID);
      > > if(Report.HasPa rameters)
      > > {
      > > CrystalReportVi ewer1.Parameter FieldInfo.Clear ();
      > > ReportParameter s pms = rpt.ReportParam eters;
      > > ParameterFields pfs = new ParameterFields ();
      > > foreach(ReportP arameter rp in pms)
      > > {
      > > ParameterField pf = new ParameterField( );
      > > ParameterDiscre teValue pv = new ParameterDiscre teValue();
      > > pf.Name = rp.ParameterNam e;
      > > // Get the value from the input
      > > string v = ReportQueryCont rol1.GetValue(r p.ParameterName );
      > > switch(rp.Value Type)
      > > {
      > > case CeReportVariabl eValueType.ceRV DateTime:
      > > try
      > > {
      > > DateTime dt = DateTime.ParseE xact(v, "MM/dd/yyyy HH:mm:ss",
      > > CultureInfo.Inv ariantCulture, DateTimeStyles. None);
      > > pv.Value = dt; // string.Format(" DateTime({0:yyy y,MM,dd,HH,mm,s s})", dt);
      > > pf.ParameterVal ueType = ParameterValueK ind.DateTimePar ameter;
      > > }
      > > catch(Exception ex)
      > > {
      > > Trace.Write("In valid date time format: " + v + " (" + ex.Message + ")");
      > > pv.Value = v;
      > > }
      > > break;
      > > case CeReportVariabl eValueType.ceRV Date:
      > > try
      > > {
      > > DateTime dt = DateTime.ParseE xact(v, "MM/dd/yyyy",
      > > CultureInfo.Inv ariantCulture, DateTimeStyles. None);
      > > pv.Value = dt; // string.Format(" Date({0:yyyy,MM ,dd})", dt);
      > > pf.ParameterVal ueType = ParameterValueK ind.DateParamet er;
      > > }
      > > catch(Exception ex)
      > > {
      > > Trace.Write("In valid date format: " + v + " (" + ex.Message + ")");
      > > pv.Value = v;
      > > pf.ParameterVal ueType = ParameterValueK ind.StringParam eter;
      > > }
      > > break;
      > > default:
      > > pv.Value = v;
      > > pf.ParameterVal ueType = ParameterValueK ind.StringParam eter;
      > > break;
      > > }
      > > if(pv.Value == null && !rp.EnableNullV alue)
      > > {
      > > // Ignore undefined values
      > > continue;
      > > }
      > > Trace.Write("Sh owCrystalReport (): Report " + rpt.ID + ", [" +
      > > rp.ValueType + "," + pf.ParameterVal ueType + "," + pf.ParameterVal ueKind + "]
      > > " + pf.Name + "=" + pv.Value);
      > > pf.CurrentValue s.AddValue(pv);
      > > CrystalReportVi ewer1.Parameter FieldInfo.Add(p f);
      > > }
      > > }
      > > CrystalReportVi ewer1.Enterpris eLogon = es;
      > > CrystalReportVi ewer1.ReportSou rce = rs;
      > > CrystalReportVi ewer1.Visible = true;
      > >[/color][/color]

      Comment

      • javatopia

        #4
        RE: CrystalReports: Value does not fall within the expected range.

        I do not see any methods that are "DataDefinition " or
        ParameterField. ApplyCurrentVal ues. 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 ParameterFieldI nfo attribute.

        CrystalDecision s.Enterprise.De sktop.Report is the report class I use

        CrystalDecision s.Web.CrystalRe portViewer is the viewer I use

        CrystalDecision s.Web.dll v 10.0.3300.0 is my version

        -- Jake


        "Elton W" wrote:
        [color=blue]
        > Try following code to assign parameter to CR report:
        >
        > ParameterDiscre teValue discretevalue = new ParameterDiscre teValue();
        > discretevalue.V alue = objValue; // Assign parameter
        > ParameterValues values = new ParameterValues ();
        > values.Add(disc retevalue);
        > crReport.DataDe finition.Parame terFields[i].ApplyCurrentVa lues(values);
        >
        > HTH
        >
        > Elton Wang
        >
        > "javatopia" wrote:
        >[color=green]
        > > What's even more odd is this stack trace from the error:
        > >
        > > System.Argument Exception: Value does not fall within the expected range.
        > > at CrystalDecision s.Shared.Shared Utils.ConvertTo Decimal(Object value)
        > > at CrystalDecision s.Shared.Parame terValues.AddVa lue(Object value)
        > > at AGIA.Enterprise Reports.ViewRep ort.ShowCrystal Report() in
        > > j:\cvsroot\clie nts\arrowhead\e nterprisereport ing\www\viewrep ort.aspx.cs:lin e
        > > 381
        > >
        > > The report is configured for a Date property (StartBookDate) .
        > >
        > > -- Jake
        > >
        > >
        > > "javatopia" wrote:
        > >[color=darkred]
        > > > 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();
        > > > EnterpriseSessi on es = sm.Logon(uname, pwd, cms, auth);
        > > > //
        > > > // Discover the crystal ID of the report to view
        > > > //
        > > > EnterpriseServi ce service = es.GetService(" InfoStore");
        > > > InfoStore info = new InfoStore(servi ce);
        > > > string query = "Select * From CI_INFOOBJECTS Where SI_PROGID =
        > > > 'CrystalEnterpr ise.Report' AND SI_ID=" + ReportID + " AND SI_INSTANCE = 0";
        > > > InfoObjects objs = info.Query(quer y);
        > > > //
        > > > // Setup the report and parameters.
        > > > //
        > > > if(objs.Count > 0)
        > > > {
        > > > // The InfoObjects collection is '1' based, not '0' based.
        > > > Report rpt = (Report)objs[1];
        > > > EnterpriseServi ce es2 = es.GetService(" PSReportFactory ");
        > > > PSReportFactory ps = (PSReportFactor y)es2.Interface ;
        > > > ReportSource rs = ps.OpenReportSo urce(rpt.ID);
        > > > if(Report.HasPa rameters)
        > > > {
        > > > CrystalReportVi ewer1.Parameter FieldInfo.Clear ();
        > > > ReportParameter s pms = rpt.ReportParam eters;
        > > > ParameterFields pfs = new ParameterFields ();
        > > > foreach(ReportP arameter rp in pms)
        > > > {
        > > > ParameterField pf = new ParameterField( );
        > > > ParameterDiscre teValue pv = new ParameterDiscre teValue();
        > > > pf.Name = rp.ParameterNam e;
        > > > // Get the value from the input
        > > > string v = ReportQueryCont rol1.GetValue(r p.ParameterName );
        > > > switch(rp.Value Type)
        > > > {
        > > > case CeReportVariabl eValueType.ceRV DateTime:
        > > > try
        > > > {
        > > > DateTime dt = DateTime.ParseE xact(v, "MM/dd/yyyy HH:mm:ss",
        > > > CultureInfo.Inv ariantCulture, DateTimeStyles. None);
        > > > pv.Value = dt; // string.Format(" DateTime({0:yyy y,MM,dd,HH,mm,s s})", dt);
        > > > pf.ParameterVal ueType = ParameterValueK ind.DateTimePar ameter;
        > > > }
        > > > catch(Exception ex)
        > > > {
        > > > Trace.Write("In valid date time format: " + v + " (" + ex.Message + ")");
        > > > pv.Value = v;
        > > > }
        > > > break;
        > > > case CeReportVariabl eValueType.ceRV Date:
        > > > try
        > > > {
        > > > DateTime dt = DateTime.ParseE xact(v, "MM/dd/yyyy",
        > > > CultureInfo.Inv ariantCulture, DateTimeStyles. None);
        > > > pv.Value = dt; // string.Format(" Date({0:yyyy,MM ,dd})", dt);
        > > > pf.ParameterVal ueType = ParameterValueK ind.DateParamet er;
        > > > }
        > > > catch(Exception ex)
        > > > {
        > > > Trace.Write("In valid date format: " + v + " (" + ex.Message + ")");
        > > > pv.Value = v;
        > > > pf.ParameterVal ueType = ParameterValueK ind.StringParam eter;
        > > > }
        > > > break;
        > > > default:
        > > > pv.Value = v;
        > > > pf.ParameterVal ueType = ParameterValueK ind.StringParam eter;
        > > > break;
        > > > }
        > > > if(pv.Value == null && !rp.EnableNullV alue)
        > > > {
        > > > // Ignore undefined values
        > > > continue;
        > > > }
        > > > Trace.Write("Sh owCrystalReport (): Report " + rpt.ID + ", [" +
        > > > rp.ValueType + "," + pf.ParameterVal ueType + "," + pf.ParameterVal ueKind + "]
        > > > " + pf.Name + "=" + pv.Value);
        > > > pf.CurrentValue s.AddValue(pv);
        > > > CrystalReportVi ewer1.Parameter FieldInfo.Add(p f);
        > > > }
        > > > }
        > > > CrystalReportVi ewer1.Enterpris eLogon = es;
        > > > CrystalReportVi ewer1.ReportSou rce = rs;
        > > > CrystalReportVi ewer1.Visible = true;
        > > >[/color][/color][/color]

        Comment

        • javatopia

          #5
          RE: CrystalReports: Value does not fall within the expected range.

          Found a solution:

          // Create the document
          CrystalDecision s.CrystalReport s.Engine.Report Document myReportDocumen t;

          myReportDocumen t = new
          CrystalDecision s.CrystalReport s.Engine.Report Document();
          myReportDocumen t.EnterpriseLog onInfo.Authenti cationType = auth;
          myReportDocumen t.EnterpriseLog onInfo.CmsServe r = cms;
          myReportDocumen t.EnterpriseLog onInfo.Username =
          uname; myReportDocumen t.EnterpriseLog onInfo.Password = pwd;
          myReportDocumen t.FileName = "ceis://@" + cms + "/#" + ReportID;
          myReportDocumen t.UriIsUserEdit able = 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( );

          myReportDocumen t.SetDatabaseLo gon(ci.UserID, ci.Password, ci.ServerName,
          ci.DatabaseName );

          CrystalReportVi ewer1.LogOnInfo .Add(CrystalLog onInfo);

          // 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 )
          {
          myReportDocumen t.SetParameterV alue(key, hashParams[key]);
          }

          // Make the report visible

          CrystalReportVi ewer1.ReportSou rce = myReportDocumen t;
          CrystalReportVi ewer1.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

          Comment

          Working...