cancel
Showing results for 
Search instead for 
Did you mean: 

parameterfieldcurrentvalueexception error message

Former Member
0 Kudos

Hi,

I have the following code working fine when the Crystal Report displays in the viewer. Now we want to send the document directly to PDF or Excel. I've added the memorystream code below the normal code and now I get the error message:

parameterfieldcurrentvalueexception was unhandled by user code - Missing parameter values.

I get the error on the line:

oStream = (MemoryStream)objReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

Please Help!

Thanks,

Darla

Code:

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using System.Data.SqlClient;

using System.IO;

namespace CapNGoCSharp

{

public partial class _Default : System.Web.UI.Page

{

ReportDocument objReport = new ReportDocument();

ParameterField paramField = new ParameterField();

ParameterFields paramFields = new ParameterFields();

ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

TableLogOnInfos crtableLogonInfos = new TableLogOnInfos();

TableLogOnInfo crtableLogoInfo = new TableLogOnInfo();

ConnectionInfo crConnectionInfo = new ConnectionInfo();

Tables crTables;

Sections crSections;

SubreportObject crSubreportObject;

ReportObjects crReportObjects;

ReportDocument crSubreportDocument;

Database crDatabase;

string sReportName;

int iReportID;

string ReportPath;

string userID;

string expenseReportID;

int iNumberOfParams;

bool notes = true;

protected void Page_Load(object sender, EventArgs e)

{

}

private void Page_Init(object sender, EventArgs e)

{

ConfigureCrystalReports();

}

private void ConfigureCrystalReports()

{

if (!IsPostBack || true)

{

//

// Get report info

//

userID = "04FC3B17-00B9-4F7C-88F2-D9888744F8B9";

expenseReportID = "FD5AAEBD-1B43-441A-B2FE-7A6E3911253E";

iReportID = 1;

bool Notes = true;

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings ["CngConnectionString"].ConnectionString);

// SqlConnection conn = new SqlConnection("Data Source=localhost;Database=Cng;Integrated Security=SSPI");

SqlCommand command = new SqlCommand("spGetReportInfo", conn);

command.CommandType = CommandType.StoredProcedure;

command.Parameters.Add("@ReportID", SqlDbType.Int).Value = iReportID;

SqlDataAdapter adapter = new SqlDataAdapter(command);

DataSet ds = new DataSet();

DataTable myDataTable = new DataTable();

//

// Fill the Adapter

//

adapter.Fill(ds, "Reports");

//

// Get the report name

// Need first record only

//

foreach (DataRow row in ds.Tables["Reports"].Rows)

{

sReportName = (string)row["ReportName"];

iNumberOfParams = (int)row["NumberOfParams"];

ReportPath = Server.MapPath(sReportName);

break;

}

//

//Get the Report Parameters

//

string[] aryParamType = new string[iNumberOfParams];

string[] aryParamVariable = new string[iNumberOfParams];

string[] aryParamName = new string[iNumberOfParams];

int i = 0;

foreach (DataRow row in ds.Tables["Reports"].Rows)

{

aryParamType<i> = (string)row["ParamType"];

if (String.Compare(aryParamType<i>, "text", true) == 0)

{

aryParamVariable<i> = (string)row["VariableName"];

aryParamName<i> = (string)row["ParamName"];

}

else

{

aryParamVariable<i> = (string)row["VariableName"];

aryParamName<i> = (string)row["ParamName"];

}

i = i + 1;

sReportName = (string)row["ReportName"];

iNumberOfParams = (int)row["NumberOfParams"];

}

ReportPath = Server.MapPath(sReportName);

//

// Set the Parameter Values

// Man, that's a lot of brackets!

//

{

int j = 0;

try

{

if (iNumberOfParams > 0)

{

paramField = new ParameterField();

paramField.Name = aryParamName[0];

for (j = 0; j < iNumberOfParams; j++)

{

if (j > 0)

{

paramField = new ParameterField();

paramField.Name = aryParamName[j];

}

if (aryParamVariable[j] == "userID")

{

paramDiscreteValue = new ParameterDiscreteValue();

paramDiscreteValue.Value = userID;

}

else

{

if (aryParamVariable[j] == "expenseReportID")

{

paramDiscreteValue = new ParameterDiscreteValue();

paramDiscreteValue.Value = expenseReportID;

}

else

{

if (aryParamVariable[j] == "notes") ;

{

paramDiscreteValue.Value = new ParameterDiscreteValue();

paramDiscreteValue.Value = Notes;

}

}

}

paramField.CurrentValues.Add(paramDiscreteValue);

paramFields.Add(paramField);

}

}

}

catch (InvalidCastException ex)

{

throw new Exception(ex.Message.ToString());

}

finally

{

}

}

}

//

// Add the Parameters

//

CrystalReportViewer1.ParameterFieldInfo = paramFields;

objReport.Load(ReportPath);

//

//Connection Info

//

crConnectionInfo.ServerName = ConfigurationManager.AppSettings["cngServer"];

crConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["cngDatabase"];

crConnectionInfo.UserID = ConfigurationManager.AppSettings["cngUserID"];

crConnectionInfo.Password = ConfigurationManager.AppSettings["cngPassword"];

crConnectionInfo.IntegratedSecurity = true;

crConnectionInfo.Type = ConnectionInfoType.SQL;

crDatabase = objReport.Database;

//

// Logon to the tables

//

crTables = objReport.Database.Tables;

foreach (CrystalDecisions.CrystalReports.Engine.Table crtable in crTables)

{

crtableLogoInfo = crtable.LogOnInfo;

crtableLogoInfo.ConnectionInfo = crConnectionInfo;

crtable.ApplyLogOnInfo(crtableLogoInfo);

crtable.Location = "dbo." + crtable.Location.Substring(crtable.Location.LastIndexOf(".") + 1);

}

//

// Logon to the subreports

//

crSections = objReport.ReportDefinition.Sections;

//

// Loop through all the sections to find all the report objects

//

foreach (Section crSection in crSections)

{

crReportObjects = crSection.ReportObjects;

//

//Loop through all the report objects in there to find all subreports

//

foreach (ReportObject crReportObject in crReportObjects)

{

if (crReportObject.Kind == ReportObjectKind.SubreportObject)

{

crSubreportObject = (SubreportObject)crReportObject;

//

//Open the subreport object and logon as for the general report

//

crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

crDatabase = crSubreportDocument.Database;

crTables = crDatabase.Tables;

foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables)

{

crtableLogoInfo = aTable.LogOnInfo;

crtableLogoInfo.ConnectionInfo = crConnectionInfo;

aTable.ApplyLogOnInfo(crtableLogoInfo);

aTable.Location = "dbo." + aTable.Location.Substring(aTable.Location.LastIndexOf(".") + 1);

}

}

}

}

//

// Set the Report Source

//

CrystalReportViewer1.ReportSource = objReport;

// objReport.Refresh();

MemoryStream oStream; // using System.IO

oStream = (MemoryStream)objReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

Response.Clear();

Response.Buffer = true;

Response.ContentType = "application/pdf";

Response.BinaryWrite(oStream.ToArray());

Response.Flush();

Response.Close();

Response.End();

objReport.Dispose();

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Darla, two things;

Remember to search the kbase and this forum before posting. A quick search for "Missing parameter values crystal net", came up with the following kbases:

[1244475 - Error: Missing parameter value when exporting a Crystal Report with optional parameters using the CR .NET SDK|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_dev/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do]

[1215426 - Err Msg: "Missing parameter value" when printing or exporting in VS .NET|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_dev/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do]

[1215536 - Err Msg: "Missing parameter field current value" when exporting/printing in .NET|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do]

[1216546 - Err Msg: "Missing Parameter Field Current Value" when viewing a report in VS.NET|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do]

Also, remember to add info such as version of CR, SPs, FPs, version of .NET. And, keep the posts to under 1200 chars, otherwise the formatting gets lost. If the post needs to be over 1200 chars, break it up into two posts.

Ludek

Follow us on Twitter http://twitter.com/SAPCRNetSup

Former Member
0 Kudos

Hi Ludek,

Thanks so much for the advice and links. That solved my issue.

Best Regards,

Darla

former_member183750
Active Contributor
0 Kudos

Excellent. Great news.

Ludek

Answers (0)