Crystal reports error : Index was out of range.
I am trying to running a crystal report 8.0 in .NET C# based on a Oracle stored procedure that accepts two parameters. I get this error "Index
was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index" on the line: crParameterField1 =
CrystalReportViewer3.ParameterFieldInfo[0];.
Here is my code:
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer3;
OracleReport3 crReportDocument = new OracleReport3();
TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
//Crystal Report Properties
protected CrystalDecisions.CrystalReports.Engine.Database crDatabase;
protected CrystalDecisions.CrystalReports.Engine.Tables crTables;
protected ParameterFields crParameterFields;
protected ParameterField crParameterField1;
protected ParameterField crParameterField2;
protected ParameterValues crParameterValues;
protected ParameterDiscreteValue crParameterDiscreteValue1;
protected ParameterDiscreteValue crParameterDiscreteValue2;
private void Page_Load(object sender, System.EventArgs e)
{
string empid, perm;
empid = (string)Session["empid"];
perm = (string)Session["perm"];
crConnectionInfo.UserID = "userid";
crConnectionInfo.Password = "password";
crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;
foreach(CrystalDecisions.CrystalReports.Engine.Tab le crTable in crTables)
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
}
CrystalReportViewer3.ReportSource= crReportDocument;
crParameterField1 = CrystalReportViewer3.ParameterFieldInfo[0];
crParameterField2 = CrystalReportViewer3.ParameterFieldInfo[1];
crParameterDiscreteValue1 = new ParameterDiscreteValue();
crParameterDiscreteValue2 = new ParameterDiscreteValue();
crParameterDiscreteValue1.Value = "emp_id";
crParameterDiscreteValue2.Value = "emp_perm";
crParameterField1.CurrentValues.Add(empid);
crParameterField2.CurrentValues.Add(perm);
}
Can someone please help?
|