By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,694 Members | 2,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,694 IT Pros & Developers. It's quick & easy.

More Questions about programming Crystal Reports...

P: n/a
Using ideas provided by some of you I was able to figure out how to get the
names of the parameters fields of a crystal report specified at run time.

The code below just basically puts the data into a comboBox. One thing I
noticed, however, is that this method shows me both the parameters used by
the main report and parameters used by the sub-report(s).

I really only need to concentrate on parameter values from the main report
in order to build my application because I know that the parameters of the
sub reports are filled with data from the main report.

Questions:

Is there a way to distinguish what parameters belong where?

What report object would I need to manipulate if my reports primarily
utilize the Database Expert Command object to build queries?

/=====================================

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Data.SqlClient;

using System.IO;

using CDCRV = CrystalDecisions.Windows.Forms.CrystalReportViewer ;

using CDCRE = CrystalDecisions.CrystalReports.Engine;

using CDS = CrystalDecisions.Shared;

namespace ReportManager

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Data.SqlClient.SqlConnection sqlConnection1;

private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;

private System.Data.SqlClient.SqlCommand sqlSelectCommand1;

private System.Data.SqlClient.SqlCommand sqlInsertCommand1;

private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;

private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;

private ReportManager.DataSet1 dataSet11;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.TabControl tabControl1;

private System.Windows.Forms.TabPage tabPage1;

private System.Windows.Forms.TabPage tabPage2;

private System.Windows.Forms.StatusBar statusBar1;

private System.Windows.Forms.StatusBarPanel statusBarPanel1;

// Crystal Objects

private CrystalDecisions.Windows.Forms.CrystalReportViewer
crystalReportViewer1;

protected CDCRE.ReportDocument RDoc1 = new
CrystalDecisions.CrystalReports.Engine.ReportDocum ent();

protected CDCRE.ParameterFieldDefinitions crParameterFieldDefinitions;

protected CDCRE.ParameterFieldDefinition crParameterFieldDefinition;

protected CDS.ParameterValues crParameterValues;

protected CDS.ParameterDiscreteValue crParameterDiscreteValue;

private System.Windows.Forms.ComboBox comboBox1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after
InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

System.Configuration.AppSettingsReader configurationAppSettings =
new System.Configuration.AppSettingsReader();

this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();

this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();

this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();

this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();

this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();

this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();

this.dataSet11 = new ReportManager.DataSet1();

this.button1 = new System.Windows.Forms.Button();

this.tabControl1 = new System.Windows.Forms.TabControl();

this.tabPage1 = new System.Windows.Forms.TabPage();

this.crystalReportViewer1 = new
CrystalDecisions.Windows.Forms.CrystalReportViewer ();

this.tabPage2 = new System.Windows.Forms.TabPage();

this.statusBar1 = new System.Windows.Forms.StatusBar();

this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();

this.comboBox1 = new System.Windows.Forms.ComboBox();

((System.ComponentModel.ISupportInitialize)(this.d ataSet11)).BeginInit();

this.tabControl1.SuspendLayout();

this.tabPage1.SuspendLayout();

this.tabPage2.SuspendLayout();

((System.ComponentModel.ISupportInitialize)(this.s tatusBarPanel1)).BeginInit();

this.SuspendLayout();

//

// sqlConnection1

//

this.sqlConnection1.ConnectionString = "workstation
id=MQDEV3;packet size=4096;user id=so404;data source=mqdev3;persist s" +

"ecurity info=True;initial catalog=so404;password=so404";

//

// sqlDataAdapter1

//

this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;

this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;

this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;

this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table",
"period", new System.Data.Common.DataColumnMapping[] {

new
System.Data.Common.DataColumnMapping("id", "id"),

new
System.Data.Common.DataColumnMapping("name", "name"),

new
System.Data.Common.DataColumnMapping("state", "state"),

new
System.Data.Common.DataColumnMapping("order_index" , "order_index"),

new
System.Data.Common.DataColumnMapping("root_org_id" , "root_org_id"),

new
System.Data.Common.DataColumnMapping("meth_org_id" , "meth_org_id"),

new
System.Data.Common.DataColumnMapping("lib_org_id", "lib_org_id"),

new
System.Data.Common.DataColumnMapping("original_id" , "original_id")})});

this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;

//

// sqlDeleteCommand1

//

this.sqlDeleteCommand1.CommandText = @"DELETE FROM period WHERE (id
= @Original_id) AND (lib_org_id = @Original_lib_org_id OR
@Original_lib_org_id IS NULL AND lib_org_id IS NULL) AND (meth_org_id =
@Original_meth_org_id) AND (name = @Original_name OR @Original_name IS NULL
AND name IS NULL) AND (order_index = @Original_order_index) AND (original_id
= @Original_original_id OR @Original_original_id IS NULL AND original_id IS
NULL) AND (root_org_id = @Original_root_org_id) AND (state =
@Original_state)";

this.sqlDeleteCommand1.Connection = this.sqlConnection1;

this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_id",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "id",
System.Data.DataRowVersion.Original, null));

this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_lib_ org_id",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "lib_org_id",
System.Data.DataRowVersion.Original, null));

this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_meth _org_id",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "meth_org_id",
System.Data.DataRowVersion.Original, null));

this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_name ",
System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "name",
System.Data.DataRowVersion.Original, null));

this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_orde r_index",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "order_index",
System.Data.DataRowVersion.Original, null));

this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_orig inal_id",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "original_id",
System.Data.DataRowVersion.Original, null));

this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_root _org_id",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "root_org_id",
System.Data.DataRowVersion.Original, null));

this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_stat e",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "state",
System.Data.DataRowVersion.Original, null));

//

// sqlInsertCommand1

//

this.sqlInsertCommand1.CommandText = @"INSERT INTO period(id, name,
state, order_index, root_org_id, meth_org_id, lib_org_id, original_id)
VALUES (@id, @name, @state, @order_index, @root_org_id, @meth_org_id,
@lib_org_id, @original_id); SELECT id, name, state, order_index,
root_org_id, meth_org_id, lib_org_id, original_id FROM period WHERE (id =
@id)";

this.sqlInsertCommand1.Connection = this.sqlConnection1;

this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.Int, 4,
"id"));

this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.VarChar,
50, "name"));

this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@state", System.Data.SqlDbType.Int, 4,
"state"));

this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@order_index",
System.Data.SqlDbType.Int, 4, "order_index"));

this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@root_org_id",
System.Data.SqlDbType.Int, 4, "root_org_id"));

this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@meth_org_id",
System.Data.SqlDbType.Int, 4, "meth_org_id"));

this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@lib_org_id", System.Data.SqlDbType.Int,
4, "lib_org_id"));

this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@original_id",
System.Data.SqlDbType.Int, 4, "original_id"));

//

// sqlSelectCommand1

//

this.sqlSelectCommand1.CommandText = "SELECT id, name, state,
order_index, root_org_id, meth_org_id, lib_org_id, origin" +

"al_id FROM period";

this.sqlSelectCommand1.Connection = this.sqlConnection1;

//

// sqlUpdateCommand1

//

this.sqlUpdateCommand1.CommandText = @"UPDATE period SET id = @id,
name = @name, state = @state, order_index = @order_index, root_org_id =
@root_org_id, meth_org_id = @meth_org_id, lib_org_id = @lib_org_id,
original_id = @original_id WHERE (id = @Original_id) AND (lib_org_id =
@Original_lib_org_id OR @Original_lib_org_id IS NULL AND lib_org_id IS NULL)
AND (meth_org_id = @Original_meth_org_id) AND (name = @Original_name OR
@Original_name IS NULL AND name IS NULL) AND (order_index =
@Original_order_index) AND (original_id = @Original_original_id OR
@Original_original_id IS NULL AND original_id IS NULL) AND (root_org_id =
@Original_root_org_id) AND (state = @Original_state); SELECT id, name,
state, order_index, root_org_id, meth_org_id, lib_org_id, original_id FROM
period WHERE (id = @id)";

this.sqlUpdateCommand1.Connection = this.sqlConnection1;

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.Int, 4,
"id"));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.VarChar,
50, "name"));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@state", System.Data.SqlDbType.Int, 4,
"state"));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@order_index",
System.Data.SqlDbType.Int, 4, "order_index"));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@root_org_id",
System.Data.SqlDbType.Int, 4, "root_org_id"));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@meth_org_id",
System.Data.SqlDbType.Int, 4, "meth_org_id"));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@lib_org_id", System.Data.SqlDbType.Int,
4, "lib_org_id"));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@original_id",
System.Data.SqlDbType.Int, 4, "original_id"));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_lib_ org_id",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "lib_org_id",
System.Data.DataRowVersion.Original, null));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_meth _org_id",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "meth_org_id",
System.Data.DataRowVersion.Original, null));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_name ",
System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "name",
System.Data.DataRowVersion.Original, null));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_orde r_index",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "order_index",
System.Data.DataRowVersion.Original, null));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_orig inal_id",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "original_id",
System.Data.DataRowVersion.Original, null));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_root _org_id",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "root_org_id",
System.Data.DataRowVersion.Original, null));

this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_stat e",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false,
((System.Byte)(0)), ((System.Byte)(0)), "state",
System.Data.DataRowVersion.Original, null));

//

// dataSet11

//

this.dataSet11.DataSetName = "DataSet1";

this.dataSet11.Locale = new
System.Globalization.CultureInfo("en-US");

//

// button1

//

this.button1.Location = new System.Drawing.Point(624, 8);

this.button1.Name = "button1";

this.button1.TabIndex = 1;

this.button1.Text = "Open File";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// tabControl1

//

this.tabControl1.AllowDrop = true;

this.tabControl1.Controls.Add(this.tabPage1);

this.tabControl1.Controls.Add(this.tabPage2);

this.tabControl1.Location = new System.Drawing.Point(8, 40);

this.tabControl1.Name = "tabControl1";

this.tabControl1.SelectedIndex = 0;

this.tabControl1.Size = new System.Drawing.Size(696, 440);

this.tabControl1.TabIndex = 2;

//

// tabPage1

//

this.tabPage1.Controls.Add(this.crystalReportViewe r1);

this.tabPage1.Location = new System.Drawing.Point(4, 22);

this.tabPage1.Name = "tabPage1";

this.tabPage1.Size = new System.Drawing.Size(688, 414);

this.tabPage1.TabIndex = 0;

this.tabPage1.Text = "Viewer";

this.tabPage1.Click += new
System.EventHandler(this.tabPage1_Click);

//

// crystalReportViewer1

//

this.crystalReportViewer1.ActiveViewIndex = -1;

this.crystalReportViewer1.AllowDrop = true;

this.crystalReportViewer1.AutoScroll =
((bool)(configurationAppSettings.GetValue("crystal ReportViewer1.AutoScroll",
typeof(bool))));

this.crystalReportViewer1.DisplayGroupTree = false;

this.crystalReportViewer1.DisplayToolbar = false;

this.crystalReportViewer1.Font = new System.Drawing.Font("Tahoma",
8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));

this.crystalReportViewer1.Location = new System.Drawing.Point(8,
16);

this.crystalReportViewer1.Name = "crystalReportViewer1";

this.crystalReportViewer1.ReportSource = null;

this.crystalReportViewer1.Size = new System.Drawing.Size(680, 384);

this.crystalReportViewer1.TabIndex = 0;

//

// tabPage2

//

this.tabPage2.Controls.Add(this.comboBox1);

this.tabPage2.Location = new System.Drawing.Point(4, 22);

this.tabPage2.Name = "tabPage2";

this.tabPage2.Size = new System.Drawing.Size(688, 414);

this.tabPage2.TabIndex = 1;

this.tabPage2.Text = "Parameters";

//

// statusBar1

//

this.statusBar1.Location = new System.Drawing.Point(0, 463);

this.statusBar1.Name = "statusBar1";

this.statusBar1.Panels.AddRange(new
System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1});

this.statusBar1.Size = new System.Drawing.Size(720, 22);

this.statusBar1.TabIndex = 3;

this.statusBar1.Text = "statusBar1";

//

// statusBarPanel1

//

this.statusBarPanel1.Width = 680;

//

// comboBox1

//

this.comboBox1.Location = new System.Drawing.Point(24, 16);

this.comboBox1.Name = "comboBox1";

this.comboBox1.Size = new System.Drawing.Size(192, 21);

this.comboBox1.TabIndex = 0;

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(720, 485);

this.Controls.Add(this.statusBar1);

this.Controls.Add(this.tabControl1);

this.Controls.Add(this.button1);

this.Name = "Form1";

this.Text = "Form1";

((System.ComponentModel.ISupportInitialize)(this.d ataSet11)).EndInit();

this.tabControl1.ResumeLayout(false);

this.tabPage1.ResumeLayout(false);

this.tabPage2.ResumeLayout(false);

((System.ComponentModel.ISupportInitialize)(this.s tatusBarPanel1)).EndInit();

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}

private void button1_Click(object sender, System.EventArgs e)

{

// Displays an OpenFileDialog so the user can select a Cursor.

OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.Filter = "Report Files (*.rpt)|*.rpt";

openFileDialog1.Title = "Select a Report File";

// Show the Dialog.

// If the user clicked OK in the dialog and

// a .RPT file was selected, open it.

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

RDoc1.Load(openFileDialog1.FileName);

//Get the collection of parameters from the report

crParameterFieldDefinitions =
RDoc1.DataDefinition.ParameterFields;

comboBox1.Items.Clear();

//Access the specified parameter from the collection

for (int i =0; i < crParameterFieldDefinitions.Count;i++)

{

crParameterFieldDefinition = crParameterFieldDefinitions[i];

comboBox1.Items.Add(crParameterFieldDefinition.Nam e );

}

// This code assigns the report file to the viewer, but

// I need to figure out how to read and then set all the other

// necessary data beforehand.

//crystalReportViewer1.ReportSource = RDoc1;



}

}



}

}


Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.