Print Page | Close Window

Missing Parameter Values

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=875
Printed Date: 20 Apr 2024 at 3:26am


Topic: Missing Parameter Values
Posted By: googly69
Subject: Missing Parameter Values
Date Posted: 18 Jun 2007 at 9:12am
I'm getting the "Missing Parameter Values." error when I try to pass a value from a drop down list into the report.  The report itself is based on a stored proc.  I'm a newbie to .Net and I've been stumbling along trying to piece together this stuff.  I can view the value of the parameter until it's passed into the report (which is viewed in a crystal report viewer control on another page)  Any help in this matter is greatly appreciated.  My code is as follows:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;


public partial class utilrptview : System.Web.UI.Page
{
    protected void SetParameterFields()
{
    ReportDocument rpt = new ReportDocument();
    rpt.Load(Server.MapPath("Reports\\util2.rpt"));
ParameterFields paramFields = CrystalReportViewer1.ParameterFieldInfo;
ParameterField paramField = paramFields["@machineid"];
ParameterValues curValues = paramField.CurrentValues;
ParameterDiscreteValue discreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();

discreteValue.Value = Request.QueryString["machineid"];
curValues.Add(discreteValue);      
CrystalReportViewer1.ParameterFieldInfo = paramFields;

   
 //.ApplyCurrentValues(curValues);
      
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument rpt = new ReportDocument();
        rpt.Load(Server.MapPath("Reports\\util2.rpt"));

        //  Get connection settings from AppSettings in Web.Config
        string strConnInfo = ConfigurationManager.AppSettings["CrystalReportConnection"].ToString();
        string[] connValues = strConnInfo.Split(';');
        string serverName = connValues[0];
        string dbName = connValues[1];
        string userID = connValues[2];
        string password = connValues[3];
          
        rpt.SetDatabaseLogon(userID, password);
        ReportLogOn();
        //rpt.Refresh();
        SetParameterFields();
        CrystalReportViewer1.ReportSource = rpt;
       

    }
    private void ReportLogOn()
    {

        TableLogOnInfos tableLogOnInfos = new TableLogOnInfos();//CrystalReportViewer1.LogOnInfo;
        string strConnInfo = ConfigurationManager.AppSettings["CrystalReportConnection"].ToString();
        string[] connValues = strConnInfo.Split(';');
        string serverName = connValues[0];
        string dbName = connValues[1];
        string userID = connValues[2];
        string password = connValues[3];

        ConnectionInfo connectionInfo = new ConnectionInfo();
        connectionInfo.ServerName = serverName;
        connectionInfo.DatabaseName = dbName;
        connectionInfo.UserID = userID;
        connectionInfo.Password = password;
        TableLogOnInfo tbl = new TableLogOnInfo();

        tbl.ConnectionInfo = connectionInfo;
        tableLogOnInfos.Add(tbl);
        CrystalReportViewer1.LogOnInfo = tableLogOnInfos;
       
    }

    protected void CrystalReportViewer1_Init(object sender, EventArgs e)
    {

    }
}



Replies:
Posted By: hilfy
Date Posted: 21 Jun 2007 at 4:44pm

It looks like you're not completely setting the parameter.  Here's a code snippet for how we set parameters:

ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
ParameterRangeValue rangeVal = new ParameterRangeValue();
ParameterValues curvalues = new ParameterValues();
foreach (ParameterFieldDefinition parafld in
             crReport.DataDefinition.ParameterFields)
{
  if (parafld.DiscreteOrRangeKind.ToString() == "DiscreteValue")
  {
    discreteVal.Value =
           Request.QueryString[parafld.ParameterFieldName];
    if (discreteVal.Value != null)
    {
      curvalues.Add(discreteVal);
      parafld.ApplyCurrentValues(curvalues);
    }
  }
}
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: googly69
Date Posted: 22 Jun 2007 at 5:23am
Thank you.  I'll work this in.


Posted By: JeremyDP
Date Posted: 25 Jul 2007 at 10:10am
I have used the code (converted to VB) posted by hilfy and get the following error:
 
Failed to open a rowset. Details: ADO Error Code: 0x Source: Microsoft OLE DB Provider for SQL Server Description: Procedure or Function 'sp_xxxx' expects parameter '@ppppp', which was not supplied. SQL State: 42000 Native Error: Failed to open a rowset. Error in File
 
I am getting this same error, however it is not a result of moving from DEV to PROD.
 
I have also tried the following code:
 
Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim currValue As CrystalDecisions.Shared.ParameterValues
Dim sParValPair() As String
Dim sValue() As String
Dim iIndex As Integer
Dim crFieldDef As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions
Dim crFieldLoc As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition
ConInfo.ConnectionInfo.ServerName = modLibrary.m_sDATASOURCE
ConInfo.ConnectionInfo.DatabaseName = modLibrary.m_sDATABASE
ConInfo.ConnectionInfo.IntegratedSecurity = True
objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
crFieldDef = objReport.DataDefinition.ParameterFields
sParValPair = sParam.Split(";")
For iIndex = 0 To UBound(sParValPair)
   If InStr(sParValPair(iIndex), "=") > 0 Then
      sValue = sParValPair(iIndex).Split("=")
      crFieldLoc = crFieldDef.Item(sValue(0))
      currValue = crFieldLoc.CurrentValues
      paraValue.Value = sValue(1)
      currValue.Add(paraValue)
      crFieldLoc.ApplyCurrentValues(currValue)
   End If
Next iIndex
 
Any ideas?
 


Posted By: jkwrpc
Date Posted: 25 Jul 2007 at 6:16pm
The error is not a CR error but an ADO.net error. To troubleshoot this and these are things you may have done....
 
If these works in test but not production, make sure the execute permissions for the user have been granted.  I have failed to GRANT permissons more times than I care to admit.
 
A second thing to look at is if you are using a .Net dataobject.  Search your project code for the name of the test server. I had a similar problem and found that while I was changing the connection string in one location there were other locations that held test server connections and not production.
 
 
I would test the stored procedure by trying the value from drop down box that is raising the error. You do this by executing the stored proc and then passing the parameters, depending of database. You may be require to hand code the values and then execute the sp.
 
 
I would hard code the parameter values in the report selection formula to make certain they work there.
 
If it checks out I make certain that the data typing is correct. I have never written a CR parameter to pass through to a database parameter, but I suspect that CR having fewer datatypes creates room for errors.
 
Finally, I would step through the code to make certain everything passed is as expected. You may want to create a few objects to read the values as they being passed to be sure they are what you want.
 
Maybe there is something here that will help isolate the problem.
 
Regards
 
John W.
http://www.CustomReportWriters.net - www.CustomReportWriters.net
 
 


Posted By: jkwrpc
Date Posted: 25 Jul 2007 at 6:29pm
Here is a link that may help. Only you will know. While it does not mention the Failed to Open A Rowset Error... I read elsewhere that it does in fact have to do with that kind of error.
 
http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do;jsessionid=9C3B8E0B1B5A14A525EEBC132AEB37B9?cmd=displayKC&docType=kc&externalId=c2011464&sliceId=&dialogID=360384&stateId=1%200%20356275 - http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do;jsessionid=9C3B8E0B1B5A14A525EEBC132AEB37B9?cmd=displayKC&docType=kc&externalId=c2011464&sliceId=&dialogID=360384&stateId=1%200%20356275


Regards
 
John W.
http://www.CustomReportWriters.net - www.CustomReportWriters.net



Print Page | Close Window