Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing Parameters to SQL Stored Procedure
Message
General information
Forum:
ASP.NET
Category:
Other
Title:
Passing Parameters to SQL Stored Procedure
Miscellaneous
Thread ID:
00847799
Message ID:
00847799
Views:
63
I am trying to send parameters to Crystal report that uses these parameters for SQL stored procedure. Having a problem to do it in my generic form with various parameter names and values I ended up creating a simple test which does not work as well.
At first I was trying to send parameters with this code:
    ParameterFields paramFields = new ParameterFields();
    ParameterField paramField = new ParameterField();
    ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
    paramField.ParameterFieldName = "@source"
    discreteVal.Value = "WWW"
    paramField.CurrentValues.Add(discreteVal)
    paramFields.Add(ParameterField)
    CrystalReportViewer1.ParameterFieldInfo = ParameterFields
    CrystalReportViewer1.ReportSource = crReport
It works fine for regular report parameters without "@". CR actually checks SP parameters, but does not apply it to SP. If I skip sending one of SP parameters, CR prompts for it.
I found an example at http://support.crystaldecisions.com/library/kbase/articles/c2011787.asp?ref=devzone_netzone_howto
VB.NET program works fine, but when I translated it to C#, I got "'CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions' does not contain a definition for 'Item'" error.
I see Item via debugger, but IntelliSense does not prompt it. It prompts Item in VB.NET program. What am I missing? I am sending my complete code. Sorry it's long.
Probably I'll end up using DataSets as CR sources, but I am wondering why this program does not work. Login part works fine.

Thanks in advance

Slava
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace testcsharp
{
	public class Form1 : System.Windows.Forms.Form
	{
		private Tables crTables;
		private Table crTable;
		private TableLogOnInfo crTableLogOnInfo;
		private ConnectionInfo crConnectionInfo;
		private ParameterValues crParameterValues ;
		private ParameterDiscreteValue crParameterDiscreteValue  ;
		private ParameterFieldDefinitions crParameterFieldDefinitions  ;
		private ParameterFieldDefinition crParameterFieldDefinition  ;
		private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;

		private System.ComponentModel.Container components = null;

		#region  " Windows Form Designer generated code "
	
		public Form1()
		{
			InitializeComponent();

			CrystalReport1 oRpt = new CrystalReport1();
			crConnectionInfo.DatabaseName = "MyDB";
			crConnectionInfo.ServerName = "SQL2000.simon.rochester.edu";
			crConnectionInfo.Password = "Mypass";
			crConnectionInfo.UserID = "sa";

			crTables = oRpt.Database.Tables;

			foreach (Table crTable in crTables)
			{
				crTableLogOnInfo = crTable.LogOnInfo;
				crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
				crTable.ApplyLogOnInfo(crTableLogOnInfo);
			}
                        //***************************** 
                        // Pass the Stored Procedure parameter to the report 
                        //***************************** 
                        crParameterFieldDefinitions = oRpt.DataDefinition.ParameterFields;
                        crParameterFieldDefinition = crParameterFieldDefinitions.Item("@source");
                        crParameterValues = crParameterFieldDefinition.CurrentValues;
                        crParameterDiscreteValue = new ParameterDiscreteValue();
                        crParameterDiscreteValue.Value = "WWW";
                        crParameterValues.Add(crParameterDiscreteValue);
                        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

crystalReportViewer1.ReportSource = oRpt;
		}

		private void InitializeComponent()
		{
			this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
			this.SuspendLayout();
			// 
			// crystalReportViewer1
			// 
			this.crystalReportViewer1.ActiveViewIndex = -1;
			this.crystalReportViewer1.Location = new System.Drawing.Point(16, 8);
			this.crystalReportViewer1.Name = "crystalReportViewer1";
			this.crystalReportViewer1.ReportSource = null;
			this.crystalReportViewer1.Size = new System.Drawing.Size(488, 272);
			this.crystalReportViewer1.TabIndex = 0;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(512, 273);
			this.Controls.Add(this.crystalReportViewer1);
			this.Name = "Form1";
			this.ResumeLayout(false);

		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

	#endregion

	}
}
Reply
Map
View

Click here to load this message in the networking platform