locked
How can avoid the issue or problem of Parameter Prompting when I send parameters programaticaly or dyanmicaly? RRS feed

  • Question

  • User524898530 posted

    Hello people,

    I am developing web application in visual studio 2008 in csharp.How can avoid the issue or problem of  Parameter Prompting when I send parameters programaticaly or dyanmicaly?  I am sending the values from .net web form to crystal report but it is still asking for parameters. so when i submit second time that is when the reports is being genereated. How can i solve this problem. Please help. The code Iam using is below.

    using System;
    using System.Collections;
    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 System.Data.OleDb;
    using System.Data.OracleClient;
    using CrystalDecisions.Shared;
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Web;
    
    
    public partial class OracleReport : System.Web.UI.Page
    {
        CrystalReportViewer crViewer = new CrystalReportViewer();
        //CrystalReportSource crsource = new CrystalReportSource();
        int nItemId;
    
        protected void Page_Load(object sender, EventArgs e)
        {
            //Database Connection
            ConnectionInfo ConnInfo = new ConnectionInfo();
            {
                ConnInfo.ServerName = "127.0.0.1";
                ConnInfo.DatabaseName = "Xcodf";
                ConnInfo.UserID = "HR777";
                ConnInfo.Password = "zghshshs";
            }
            // For Each  Logon  parameters
            foreach (TableLogOnInfo cnInfo in this.CrystalReportViewer1.LogOnInfo)
            {
                cnInfo.ConnectionInfo = ConnInfo;
    
            }
    
    
    
    
    
    
            //Declaring varibles
             nItemId = int.Parse(Request.QueryString.Get("ItemId"));
            //string strStartDate = Request.QueryString.Get("StartDate");
            //int nItemId = 20;
            string strStartDate = "23-JUL-2010";
    
            // object declration
            CrystalDecisions.CrystalReports.Engine.Database crDatabase;
            CrystalDecisions.CrystalReports.Engine.Table crTable;
    
    
            TableLogOnInfo dbConn = new TableLogOnInfo();
    
            // new report document object
            ReportDocument oRpt = new ReportDocument();
    
            // loading the ItemReport in report document
            oRpt.Load("C:\\Inetpub\\wwwroot\\cryreport\\CrystalReport1.rpt");
    
            // getting the database, the table and the LogOnInfo object which holds login onformation
            crDatabase = oRpt.Database;
    
            // getting the table in an object array of one item
            object[] arrTables = new object[1];
            crDatabase.Tables.CopyTo(arrTables, 0);
    
            // assigning the first item of array to crTable by downcasting the object to Table
            crTable = (CrystalDecisions.CrystalReports.Engine.Table)arrTables[0];
    
            dbConn = crTable.LogOnInfo;
    
            // setting values
            dbConn.ConnectionInfo.DatabaseName = "Xcodf";
            dbConn.ConnectionInfo.ServerName = "127.0.0.1";
            dbConn.ConnectionInfo.UserID = "HR777";
            dbConn.ConnectionInfo.Password = "zghshshs";
    
            // applying login info to the table object
            crTable.ApplyLogOnInfo(dbConn);
    
    
    
    
    
    
            crViewer.RefreshReport();
            
                    // defining report source
            crViewer.ReportSource = oRpt;
            //CrystalReportSource1.Report = oRpt;
            
            // so uptill now we have created everything
            // what remains is to pass parameters to our report, so it
            // shows only selected records. so calling a method to set
            // those parameters.
         setReportParameters(); 
        }
    
        private void setReportParameters()
        {
         
            // all the parameter fields will be added to this collection
            ParameterFields paramFields = new ParameterFields();
             //ParameterFieldDefinitions ParaLocationContainer = new ParameterFieldDefinitions();
           //ParameterFieldDefinition ParaLocation = new ParameterFieldDefinition();
           
            // the parameter fields to be sent to the report
            ParameterField pfItemId = new ParameterField();
            //ParameterField pfStartDate = new ParameterField();
            //ParameterField pfEndDate = new ParameterField();
    
            // setting the name of parameter fields with wich they will be recieved in report
          
            pfItemId.ParameterFieldName = "RegionID";
    
            //pfStartDate.ParameterFieldName = "StartDate";
            //pfEndDate.ParameterFieldName = "EndDate";
    
            // the above declared parameter fields accept values as discrete objects
            // so declaring discrete objects
            ParameterDiscreteValue dcItemId = new ParameterDiscreteValue();
            //ParameterDiscreteValue dcStartDate = new ParameterDiscreteValue();
            //ParameterDiscreteValue dcEndDate = new ParameterDiscreteValue();
    
            // setting the values of discrete objects
            
    
              dcItemId.Value = nItemId;
            
            //dcStartDate.Value = DateTime.Parse(strStartDate);
            //dcEndDate.Value = DateTime.Parse(strEndDate);
            
            // now adding these discrete values to parameters
              //paramField.HasCurrentValue = true;
    
          
    
              //pfItemId.CurrentValues.Clear();
             int valueIDD = int.Parse(Request.QueryString.Get("ItemId").ToString());
              pfItemId.Name = valueIDD.ToString(); 
              
            pfItemId.CurrentValues.Add(dcItemId);
            //ParaLocation.ApplyCurrentValues;
            pfItemId.HasCurrentValue = true;
           
            //pfStartDate.CurrentValues.Add(dcStartDate);
            //pfEndDate.CurrentValues.Add(dcEndDate);
    
            // now adding all these parameter fields to the parameter collection
            paramFields.Add(pfItemId);
            
            //paramFields.Add(pfStartDate);
            //paramFields.Add(pfEndDate);
            /////////////////////
            //Formula from Crystal
           //crViewer.SelectionFormula = "{COUNTRIES.REGION_ID} = " + int.Parse(Request.QueryString.Get("ItemId")) + "";
            crViewer.RefreshReport();
            // finally add the parameter collection to the crystal report viewer
            crViewer.ParameterFieldInfo = paramFields;
           
            
        
        }
    }
    



    Monday, July 26, 2010 5:11 AM

All replies