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 = crReportIt 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.
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 } }