|
-
August 26th, 2009, 07:50 AM
#1
Crystal parameters problem
HI all,
I'm having a problem passing a parameter from my c-sharp code through Crystal Reports 2008...
I'm using : SharpDevelop Version : 3.1.0.4077
and Crystal Reports Developer version 12.1.0.892
The code I use calling one of the reports I must provide:
using System;
using System.Collections.Generic;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.OracleClient;
using System.Collections;
namespace CrystalReportsRapportjes
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Start of program!");
string connString = "server=CT44_PROD;user id=reports;password=reports";
OracleConnection conn = new OracleConnection(connString);
try
{
conn.Open();
Console.WriteLine("Connection opened.");
Console.WriteLine("Connection Properties:");
Console.WriteLine("\tConnection String: {0}", conn.ConnectionString);
Console.WriteLine("\tServerVersion: {0}", conn.ServerVersion);
Console.WriteLine("\tState: {0}", conn.State);
QL_ExportReport("C:\\Data\\converted2crystal\\EDC_PLANNING_REPORT_params.rpt");
} catch (OracleException e) {
Console.WriteLine("Error: " + e);
} finally {
conn.Close();
Console.WriteLine("Connection closed.");
}
Console.WriteLine("End of program!");
Console.ReadKey();
}
private static void QL_ExportReport(string reportName)
{
ReportDocument CR_reportDocument = new ReportDocument();
DataSet ds = new DataSet();
CR_reportDocument.Load(reportName);
CR_reportDocument.SetDatabaseLogon("Reports", "Reports");
for(int i=0;i<CR_reportDocument.DataDefinition.ParameterFields.Count; i++)
{
Console.WriteLine("Reading parameters");
Console.WriteLine(CR_reportDocument.DataDefinition.ParameterFields[i].ParameterFieldName);
if(CR_reportDocument.DataDefinition.ParameterFields[i].ParameterFieldName==
"Protocolname")
Console.WriteLine("Correct parameter found, now assigning value");
ParameterValues ThisPV = new ParameterValues();
ThisPV.AddValue("TMC114C229");
CR_reportDocument.DataDefinition.ParameterFields[i].CurrentValues.Clear();
CR_reportDocument.DataDefinition.ParameterFields[i].DefaultValues.Clear();
CR_reportDocument.DataDefinition.ParameterFields[i].ApplyCurrentValues(ThisPV) ;
//CR_reportDocument.SetParameterValue("Protocolname","TMC114C229");
//CR_reportDocument.DataDefinition.ParameterFields[i].CurrentValues.AddValue(ThisPV);
}
CR_reportDocument.Refresh();
CR_reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat,"C:\\Data\\converted2crystal\\EDC_PLANNING_RPT_params.pdf");
CR_reportDocument.Close();
}
}
}
The exceptions he throws using this code is = CrystalDecisions.CrystalReports.Engine.ParameterFieldCurrentValueException: Missing parameter values. ---> System.Runtime.InteropServices.COMException: Missing parameter values.
at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException
at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream
at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream
at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export
at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToDisk
at CrystalReportsRapportjes.MainClass.QL_ExportReport in c:\Data\sharpdevelopfolder\CrystalReportsRapportjes\CrystalReportsRapportjes\Program.cs:line 72
at CrystalReportsRapportjes.MainClass.Main in c:\Data\sharpdevelopfolder\CrystalReportsRapportjes\CrystalReportsRapportjes\Program.cs:line 33
When I use the code
CR_reportDocument.DataDefinition.ParameterFields[i].CurrentValues.AddValue(ThisPV);
instead of
CR_reportDocument.DataDefinition.ParameterFields[i].ApplyCurrentValues(ThisPV) ;
the error I get there is:
System.ArgumentException: Value does not fall within the expected range.
at CrystalDecisions.Shared.SharedUtils.ConvertToDecimal
at CrystalDecisions.Shared.ParameterDiscreteValue.set_Value
at CrystalDecisions.Shared.ParameterValues.AddValue
at CrystalReportsRapportjes.MainClass.QL_ExportReport in c:\Data\sharpdevelopfolder\CrystalReportsRapportjes\CrystalReportsRapportjes\Program.cs:line 69
at CrystalReportsRapportjes.MainClass.Main in c:\Data\sharpdevelopfolder\CrystalReportsRapportjes\CrystalReportsRapportjes\Program.cs:line 33
I don't know how to solve this, I'm not an expert in Csharp, rather a beginner...
Can someone please tell me what's the right way passing a parameter to a report?
Thanks in advance.
grtz
Axel
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|