[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 781
  • Last Modified:

Grabbing Parameters from Crystal XI in C# more than one parameter is declared in the report. I am populating values from Request.QueryString["URL_RECON_DTTM"].ToString();

I am trying to bring in a 2nd parameter from a crystal report that was given to me.  I need to run this report though an url.  Whatever the given values are in the URL, I am to grab them from there and generate the report.  This works fine for one parameter.  However, I cannot get it to work for two parameter fields.  I can put the values into the an array.  However, I cannot get Crystal to reconconize that there are two parameters.  Please help soon.  I am running out of ideals.

The url would like like this:

http://localhost:4256/MedRecReports/ArchiveReport.aspx?URL_PERSON_NUM=131&URL_RECON_DTTM=1/28/2008 3:13:03 PM

The URL_PERSON_NUM is a string.
The URL_RECON_DTTM is a DateTime in the Crystal report.



(ERROR MESSAGE)  

An exception of type 'System.ArgumentOutOfRangeException' occurred in CrystalDecisions.Shared.dll but was not handled in user code

Additional information: Specified argument was out of the range of valid values.

using System;
using Microsoft.VisualBasic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
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 System.Web.Configuration;
using System.Reflection;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Web;
 
public partial class ArchiveReport : System.Web.UI.Page
{
    private const string PARAMETER_FIELD_NAME = "URL_PERSON_NUM";
    private const string PARAMETER_FIELD_NAME1 = "URL_RECON_DTTM";
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    private void Page_Init(object sender, EventArgs e)
    {
		// Set Session Variable for Screen Time Out
		Session["AppAccessDate"] = DateTime.Now;	
		
        ConfigureCrystalReports();
    }
 
 
    private void ConfigureCrystalReports()
    {
 
		// The following code must be placed in every GASF Web Page
		// Compare current time to last time the app was accessed. 
		// If time in minutes from config field "HIPAAScreenRefresh" has elapsed 
		// return to GASF Home Page screen.
		System.TimeSpan diff = DateTime.Now.Subtract((DateTime)Session["AppAccessDate"]);
		int totalSeconds = (diff.Minutes) * 60 + diff.Seconds; // total difference in seconds
		if (totalSeconds > (Convert.ToInt32(WebConfigurationManager.AppSettings["HIPAAScreenRefresh"]) * 60))
		{
			Response.Redirect(WebConfigurationManager.AppSettings["Archive"]);
		}
		else
		{
			// Refresh web page after time set in Config File + 10 seconds.
			// Time Set in Config File in minutes is multipled by 60 to obtain seconds.
			// When the page is refreshed and time time has expired since the last update
			// the user is returned to the Weclome Page.
			int screenRefreshSeconds = Convert.ToInt32(WebConfigurationManager.AppSettings["HIPAAScreenRefresh"]) * 60 + 10;
			this.Response.AppendHeader("Refresh", screenRefreshSeconds.ToString());
		}
 
		// Database connection stuff
		ConnectionInfo connectionInfo = new ConnectionInfo();
		connectionInfo.ServerName = "GA_Critical_info";
		connectionInfo.DatabaseName = "GA_Critical_info";
		connectionInfo.UserID = "GGSCRITICAL";
		connectionInfo.Password = "GGSCRITICAL";
 
        ArrayList arrayList = new ArrayList();
 
        string reportPath = Server.MapPath("~/reports/Archive/admitArchive.rpt");
        crystalReportViewer.ReportSource = reportPath;
 
		SetDBLogonForReport(connectionInfo);
 
        ParameterFields parameterFields = crystalReportViewer.ParameterFieldInfo;
 
        if (!IsPostBack)
        {
			// Store User ID from Query String in ViewState
			if (Request.QueryString["URL_PERSON_NUM"] == null)
			{
				Session["URL_PERSON_NUM"] = "0";
			}
			else
			{
				Session["URL_PERSON_NUM"] = Request.QueryString["URL_PERSON_NUM"].ToString();
                Session["URL_RECON_DTTM"] = Request.QueryString["URL_RECON_DTTM"];
                string testURL = Request.QueryString["URL_PERSON_NUM"].ToString();
                string testURLD = Request.QueryString["URL_RECON_DTTM"].ToString();
			}
 
            arrayList.Add(Convert.ToInt32(Request.QueryString["URL_PERSON_NUM"]));
           // arrayList.Add(Convert.ToInt32(Request.QueryString["URL_RECON_DTTM"]));
            Session["arrayList"] = arrayList;
        }
        else
        {
			if (Session["arrayList"] == null)
			{
				Response.Redirect(WebConfigurationManager.AppSettings["Archive"]);
			}
 
            arrayList = (ArrayList)Session["arrayList"];
        }
 
        SetCurrentValuesForParameterField(parameterFields, arrayList);
 
    }
 
	private void SetDBLogonForReport(ConnectionInfo connectionInfo)
	{
		TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo;
		foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
		{
			tableLogOnInfo.ConnectionInfo = connectionInfo;
		}
	}
 
    private void SetCurrentValuesForParameterField(ParameterFields parameterFields, ArrayList arrayList)
    {
        ParameterValues currentParameterValues = new ParameterValues();
        foreach (object submittedValue in arrayList)
        {
            ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
            parameterDiscreteValue.Value = submittedValue.ToString();
            currentParameterValues.Add(parameterDiscreteValue);
        }
 
 
        ParameterField parameterField = parameterFields["URL_PERSON_NUM", "URL_RECON_DTTM"];
        parameterField.CurrentValues = currentParameterValues;
 
    }
 
    private ArrayList GetDefaultValuesFromParameterField(ParameterFields parameterFields)
    {
        ParameterField parameterField = parameterFields["URL_PERSON_NUM", "URL_RECON_DTTM"];
        ParameterValues defaultParameterValues = parameterField.DefaultValues;
        ArrayList arrayList = new ArrayList();
        foreach (ParameterValue parameterValue in defaultParameterValues)
        {
            if (!parameterValue.IsRange)
            {
                ParameterDiscreteValue parameterDiscreteValue = (ParameterDiscreteValue)parameterValue;
                arrayList.Add(parameterDiscreteValue.Value.ToString());
            }
        }
 
        return arrayList;
    }
 
    /// <summary>
    /// The method below is not needed. We commented it out for potential future use.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    //protected void redisplay_Click(object sender, EventArgs e)
    //{
    //    ArrayList arrayList = new ArrayList();
    //    foreach (ListItem item in defaultParameterValuesList.Items)
    //    {
    //        if (item.Selected)
    //        {
    //            arrayList.Add(item.Value);
    //        }
    //    }
 
    //    Session["arrayList"] = arrayList;
    //    ConfigureCrystalReports();
    //}
	protected void LinkButton1_Click(object sender, EventArgs e)
	{
		// Append URL for Admit App
		string url = string.Empty;
		string queryString = string.Empty;
		url = WebConfigurationManager.AppSettings["Archive"];
 
		// If report was started with a UserID Link to
		// Home Page of the GASF Application
		if (Session["URL_PERSON_NUM"].ToString() == "0")
		{
            queryString = "RX_ADMIT_RECON.aspx";
		}
		else
		{
			queryString = "RX_ADMIT_RECON.aspx?URL_PERSON_NUM=" + Session["URL_PERSON_NUM"].ToString();
		}
		
		Response.Redirect(url + queryString);
	}
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
 
        Response.Write("<script>window.close()</script>");
 
    }
    
}

Open in new window

0
kimmie8000
Asked:
kimmie8000
  • 3
  • 2
1 Solution
 
mlmccCommented:
Canyou pass a datetime parameter to a report as a single parameter?

I think you need to pass a datettime value not a string

mlmcc
0
 
kimmie8000Author Commented:
Right now, I am just trying to pass two parameters.  One does need to be a date and time parameter.  I have gotten this far with totally trying to turn the code around to just get the two parms to pass.  Now the Crystal report tells me that I am not generating any parameters.  At this point, I am not sure what I am doing wrong.  

 ArchiveAdmitReport = new ReportDocument();
        string reportPath = Server.MapPath("~/reports/Archive/admitArchive.rpt");
        crystalReportViewer.ReportSource = reportPath;
        ArchiveAdmitReport.Load(reportPath);
       
       
        //Connect to the ODBC Crystal report.
            SetDBLogonForReport(connectionInfo);

        ParameterFields parameterFields = crystalReportViewer.ParameterFieldInfo;
       
        if (!IsPostBack)
        {
                  // Store User ID from Query String in ViewState
                  if (Request.QueryString["URL_PERSON_NUM"] == null)
                  {
                        Session["URL_PERSON_NUM"] = "0";
                  }
                  else
                  {
                        Session["URL_PERSON_NUM"] = Request.QueryString["URL_PERSON_NUM"].ToString();
                Session["URL_RECON_DTTM"] = Request.QueryString["URL_RECON_DTTM"];
                string testURL = Request.QueryString["URL_PERSON_NUM"].ToString();
                string testURLD = Request.QueryString["URL_RECON_DTTM"].ToString();

               
                }

            arrayList.Add(Convert.ToInt32(Request.QueryString["URL_PERSON_NUM"]));
            arrayList.Add(Convert.ToInt32(Request.QueryString["URL_RECON_DTTM"]));
            Session["arrayList"] = arrayList;

           
        }
        else
        {
                  if (Session["arrayList"] == null)
                  {
                        Response.Redirect(WebConfigurationManager.AppSettings["Archive"]);
                  }

            arrayList = (ArrayList)Session["arrayList"];
        }

        SetCurrentValuesForParameterField(ArchiveAdmitReport);
       
       //SetCurrentValuesForParameterField(parameterFields, arrayList);

    }

      private void SetDBLogonForReport(ConnectionInfo connectionInfo)
      {
            TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo;
            foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
            {
                  tableLogOnInfo.ConnectionInfo = connectionInfo;
            }
      }

    private void SetCurrentValuesForParameterField(ReportDocument reportDocument)
    {
        ParameterValues currentParameterValues = new ParameterValues();
        ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
        parameterDiscreteValue.Value = Request.QueryString["URL_PERSON_NUM"].ToString();
        currentParameterValues.Add(parameterDiscreteValue);
        ParameterFieldDefinitions parameterFieldDefinitions = reportDocument.DataDefinition.ParameterFields;
        ParameterFieldDefinition parameterFieldDefinition = parameterFieldDefinitions["URL_PERSON_NUM"];
        parameterFieldDefinition.ApplyCurrentValues(currentParameterValues);



        parameterDiscreteValue.Value = Request.QueryString["URL_RECON_DTTM"].ToString();
        currentParameterValues.Add(parameterDiscreteValue);
        ParameterFieldDefinition parameterFieldDefinition2 = parameterFieldDefinitions["URL_RECON_DTTM"];
        parameterFieldDefinition.ApplyCurrentValues(currentParameterValues);
        crystalReportViewer.ReportSource = ArchiveAdmitReport;    
       
    }
0
 
kimmie8000Author Commented:
I figured this out.  thnks for letting me post.  
0
 
mlmccCommented:
What is the solution?

mlmcc
0
 
kimmie8000Author Commented:
public void SetParameterFields()
    {
       
        ParameterFields paramFields = new ParameterFields();
        // parms to be sent to the reports.
        ParameterField pfUserID = new ParameterField();
        ParameterField pfDateTime = new ParameterField();

        pfUserID.ParameterFieldName = "URL_PERSON_NUM";
        pfDateTime.ParameterFieldName = "URL_RECON_DTTM";

        ParameterDiscreteValue dcUserID = new ParameterDiscreteValue();
        ParameterDiscreteValue dcDateTime = new ParameterDiscreteValue();

        dcUserID.Value = Request.QueryString["URL_PERSON_NUM"].ToString();
        //dcDateTime.Value = Request.QueryString["URL_RECON_DTTM"].ToString();
        dcDateTime.Value = Session["URL_RECON_DTTM"];

        pfUserID.CurrentValues.Add(dcUserID);
        pfDateTime.CurrentValues.Add(dcDateTime);

        paramFields.Add(pfUserID);
        paramFields.Add(pfDateTime);

        crystalReportViewer.ParameterFieldInfo = paramFields;

        ArchiveAdmitReport1 = new ReportDocument();
        string reportPath = Server.MapPath("~/reports/ArchiveAdmit/admitArchive.rpt");
       
        ArchiveAdmitReport1.Load(reportPath);
        //Connect to the ODBC Crystal report.
        ConnectionInfo connectionInfo = new ConnectionInfo();
        connectionInfo.ServerName = "GA_Critical_info";
        connectionInfo.DatabaseName = "GA_Critical_info";
        connectionInfo.UserID = "GGSCRITICAL";
        connectionInfo.Password = "GGSCRITICAL";
        SetDBLogonForReport(connectionInfo);

        crystalReportViewer.ReportSource = ArchiveAdmitReport1;

        ArchiveAdmitReport1.SetDatabaseLogon("GGSCRITICAL", "GGSCRITICAL");



This is the subroutine that I used.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now