CrystalReports: Value does not fall within the expected range.

G

Guest

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;
 
G

Guest

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 said:
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;
 
G

Guest

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 said:
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 said:
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;
 
G

Guest

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 said:
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 said:
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 said:
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;
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,820
Messages
2,569,723
Members
45,510
Latest member
ThaliaMaxi

Latest Threads

Top