Can I create an app in Visual C# 2008 Express that can call a crystal report and pass paramaters?

J C
J C used Ask the Experts™
on
If it is possible, can anyone provide documentation or direction on how I can get started. Please let me know if further information is needed of me in order for you to be able to assist.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
No.  The Express version doesn't include the capability to call reports.

If you go to the Professional version, it includes a version of Crystal.

You may be able to call a report from the standard version but I am not sure about that.

mlmcc
IT Consultant
Top Expert 2010
Commented:
Using Express edition of Visual Studio, I don't see any reason you couldn't reference the Crystal Decisions libraries to open/display a report.

However, it does not include Crystal Reports (you would have to obtain the components elsewhere, and may require purchase of Crystal Reports separately) so you wouldn't be able to design the report in Visual Studio Express.
J C

Author

Commented:
What I am trying to do is this.

I have built a crosstab report in crystal reports for a client. I want to create an app that will allow the end user to enter the paramaters and after clicking submit to be able to pull the report up and either print or export at that point.
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

J C

Author

Commented:
Thanks for clearing up that the version of visual express will not work. Still looking for some guidance otherwise if you can provide it.
Todd GerbertIT Consultant
Top Expert 2010

Commented:
Do you have a Crystal Report already made, or do you need to create a report from scratch?
J C

Author

Commented:
I have the report already made. I have Crystal Reports 11.5 but I want to make it simpler for the end user who will need the information the report provides. I know there are solutions out there but I was hoping to save the client some money by building a small application that would handle what I need.
Todd GerbertIT Consultant
Top Expert 2010

Commented:
Then yes, you should be able to use Visual Studio Express to build a simple application that will display a report.  Your project will need to reference the Crystal Reports libraries, and you'll need to provide the end-user with the Crystal Report runtime libraries, you can download them here: http://resources.businessobjects.com/support/additional_downloads/runtime.asp
J C

Author

Commented:
Can you provide any documentation on how to do this? I've searched but I am not sure I am using the right terminology. It would be helpful if you could provide some! Either way you've answered my questions. Thanks
Todd GerbertIT Consultant
Top Expert 2010

Commented:
Are you already familiar with C# or VB.Net?
J C

Author

Commented:
I have done a few things but still consider myself a novice.
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
Todd GerbertIT Consultant
Top Expert 2010

Commented:
Here's a simple example that sets a single number parameter field and displays a report.  You'll need to Crystal reports basic for visual studio 2008 runtime I posted the link to above.  Hopefully this will get you started.

Using C# Express, create a Windows forms project.  Use Notepad to open your project's .csproj file, add the following in the <ItemGroup> section (just before the other <Reference> tags):

    <Reference Include="CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>C:\Windows\assembly\GAC_MSIL\CrystalDecisions.CrystalReports.Engine\10.5.3700.0__692fbea5521e1304\CrystalDecisions.CrystalReports.Engine.dll</HintPath>
    </Reference>
    <Reference Include="CrystalDecisions.Enterprise.Framework, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
    <Reference Include="CrystalDecisions.Enterprise.InfoStore, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
    <Reference Include="CrystalDecisions.ReportSource, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>C:\Windows\assembly\GAC_MSIL\CrystalDecisions.ReportSource\10.5.3700.0__692fbea5521e1304\CrystalDecisions.ReportSource.dll</HintPath>
    </Reference>
    <Reference Include="CrystalDecisions.Shared, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>C:\Windows\assembly\GAC_MSIL\CrystalDecisions.Shared\10.5.3700.0__692fbea5521e1304\CrystalDecisions.Shared.dll</HintPath>
    </Reference>
    <Reference Include="CrystalDecisions.Windows.Forms, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" />

Remove Form1.cs from the project.  Replace the contents of Program.cs with the code below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace MyCrystalViewer
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length != 1)
            {
                using (OpenFileDialog ofd = new OpenFileDialog())
                {
                    ofd.AutoUpgradeEnabled = true;
                    ofd.CheckFileExists = true;
                    ofd.CheckPathExists = true;
                    ofd.DefaultExt = "rpt";
                    ofd.Filter = "Report Files (*.rpt)|*.rpt|All Files (*.*)|*.*";
                    ofd.FilterIndex = 1;
                    ofd.Multiselect = false;
                    ofd.RestoreDirectory = true;

                    if (ofd.ShowDialog() != DialogResult.OK)
                        return;
                    else
                        Application.Run(new Form1(ofd.FileName));
                }
            }
            else
                Application.Run(new Form1(args[0]));
        }
    }

    public class Form1 : Form
    {
        private string _reportFile;
        private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }


        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
            this.SuspendLayout();
            // 
            // crystalReportViewer1
            // 
            this.crystalReportViewer1.ActiveViewIndex = -1;
            this.crystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.crystalReportViewer1.Location = new System.Drawing.Point(0, 0);
            this.crystalReportViewer1.Name = "crystalReportViewer1";
            this.crystalReportViewer1.SelectionFormula = "";
            this.crystalReportViewer1.Size = new System.Drawing.Size(284, 262);
            this.crystalReportViewer1.TabIndex = 0;
            this.crystalReportViewer1.ViewTimeSelectionFormula = "";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Controls.Add(this.crystalReportViewer1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

            this.Load += new EventHandler(Form1_Load);
        }

        void Form1_Load(object sender, EventArgs e)
        {
            ReportDocument report = new ReportDocument();
            report.Load(_reportFile);
            report.SetParameterValue(0, 28);

            crystalReportViewer1.ReportSource = report;
        }

        public Form1(string ReportFile)
        {
            InitializeComponent();

            _reportFile = ReportFile;
        }
    }
}

Open in new window

J C

Author

Commented:
First, thank you very much for your responses.

Secondly, I download the trial version of Visual Basic 2008 Pro and am working with it now instead of the express version. I have the crystal report application created(2008 makes it really easy to create it). Is it ok to continue asking questions about how to do certain things within the app or do you want me to create a new question since you answered my initial questions?
Todd GerbertIT Consultant
Top Expert 2010

Commented:
I'm happy to try to answer them ... but you may well have questions that others besides me can answer better, and they won't be likely to see them unless you start new questions. ;)
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
Since this question has been answered and the new questions aren't really follow ons then you should open a new question.

mlmcc
J C

Author

Commented:
My first question is. The application appears to prompt for both of the crystal report paramaters. The start date is easy, it created the control for that but the other paramater should populate from one of the fields in the database. It is the Project.Name field. I do not currently have access to the live database on my dev machine. If the person running it has access to the database, should it populate the list of Projects so that they can select it from the database or is there something that I have to add to give it the ability to do that?

Also, I would like for the end user not to be prompted for login credentials for the database. Is there a way to avoid having to setup an ODBC connection at each user's workstation by hard coding it into the application?

The database is a Progress db.

J C

Author

Commented:
tgerbert,

I can create another question and post the link to it here and maybe you can migrate over if you feel like you can help. I will ask the same question above in the new question. Thanks!
J C

Author

Commented:
Actually, I do not have enough points to ask another question. If you guys would be willing to continue helping me here that would be awesome. I did try.
Todd GerbertIT Consultant
Top Expert 2010

Commented:
If you programatically create the report document, you can set some of those options.  I'm not sure if there are other ways or not...

So, for example, in your Form_Load event:

Dim report As New ReportDocument
report.Load("MyReport.rpt")
report.DataSourceConnections(0).SetLogon("yourSqlUser", "yourSqlPassword")
crystalReportViewer1.ReportSource = report

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial