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