Solved

Crystal Report in C#

Posted on 2011-03-14
12
1,134 Views
Last Modified: 2012-05-11
I am trying to open a Crystal Report in C# 2008.  I have a report named rptJournal and a form named frmJournal with a viewer named crystalreportviewer1.  The report's data comes from a stored procedure I've linked with SQLServer.  I'm running the same thing in vb6 but seems like the syntax is different.  :)

Thanks,
Jerry
0
Comment
Question by:JDL129
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 35127934
What you want?
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 35128169
That is very true.  The .Net API is much different from the VB6 .COM API

This article will help you migrate from the RDC to the .NET assemblies
http://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/e0eb394f-931e-2b10-3b82-9413bfc3f457

mlmcc
0
 
LVL 3

Expert Comment

by:brd24gor
ID: 35128629
These two procedures should help you out. The first one I use to feed information into the report like the credentials, server, report location, etc. The second is needed to feed the credentials to each table to actually read in the report. Don't forget you'll have to import CrystalDecisions.CrystalReports.Engine and CrystalDecisions.Shared.
private void ConfigureCrystalReports()
        {
            ReportDocument report = new ReportDocument();
            report.FileName = Server.MapPath(@"your report location");

            ConnectionInfo connectionInfo = new ConnectionInfo();
            connectionInfo.ServerName = "your database server";
            connectionInfo.DatabaseName = "your database name";
            connectionInfo.UserID = "your database user id";
            connectionInfo.Password = "your database password";

            SetDBLogonForReport(connectionInfo, report);

            CrystalReportViewer1.ReportSource = report;
        }

        private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
        {
            Tables tables = reportDocument.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
            {
                TableLogOnInfo tableLogonInfo = table.LogOnInfo;
                tableLogonInfo.ConnectionInfo = connectionInfo;
                table.ApplyLogOnInfo(tableLogonInfo);
            }
        }

Open in new window

0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:JDL129
ID: 35129267
brd24gor!!!!!!!!!!!!
Thanks for the response!!

I get:
'Error      52      The type or namespace name 'ReportDocument' could not be found (are you missing a using directive or an assembly reference?)      C:\POSiTrackC\POSiTrackC\POSiTrackC\POSiTrackC\frmJournal.cs      23      13      POSiTrackC
After adding the references.

Thanks,
Jerry
0
 
LVL 3

Expert Comment

by:brd24gor
ID: 35129599
In Visual Studio (with your project open), right-click your project in the Solution Explorer and click Property Pages. Under References, do you have any Crystal Decisions entries? If so, what is the version number? If not, click on Add Reference in the Property Pages window. Find and add CrystalDecisions.CrystalReports.Engine, CrystalDecisions.ReportSource, CrystalDecisions.Shared, CrystalDecisions.Web (if using ASP.NET), and CrystalDecisions.Forms (if programming desktop application).

What version of Crystal Reports are your reports?
0
 

Author Comment

by:JDL129
ID: 35130046
brd24gor!!!!!!!!
Thanks for the response!!

I have .CrystalReports.Engine, .Enterprise.framework, .Enterprise.InfoStore, .ReportSource,
.Shared, and .Windows.Forms.  All are version 10.5.3700.0.

I have created the report with C# Crystal Reports.

I have used a stored procedure in SQLServer 2005 express for the datasource so I shouldn't need to use the data connection info should I?

Thanks again,
Jerry
0
 
LVL 3

Expert Comment

by:brd24gor
ID: 35130454
I believe you do because when you connect via Crystal Reports, the ODBC driver handles the connection. In code, you need to handle it.

ReportDocument is in CrystalDecisions.CrystalReports.Engine. As long as you have a 'using CrystalDecisions.CrystalReports.Engine' clause and the reference present, it should work.
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data.SqlClient;

Open in new window

0
 

Author Comment

by:JDL129
ID: 35130955
brd24gor!!!!!!!!!!
Thanks for hanging with me!!

After adding the System.Data.SqlClient ( I already had added the others) I'm getting an error:
The type or namespace name 'ConnectionInfo' could not be found.  What other directive or assembly reference do I need to add?

Thanks,

Jerry
0
 

Author Comment

by:JDL129
ID: 35131045
brd24gor!!!

I am also having problems with the line:
report.FileName = Server.MapPath(@"your report location");

I'm getting an error at 'Server' and I'm not quite sure how to put in my report location.  

Thanks,
Jerry
0
 
LVL 3

Expert Comment

by:brd24gor
ID: 35131125
First part: ConnectionInfo is in the CrystalDecisions.Shared library. If you have that assembly and directive then I'm not sure why the namespace isn't being recognized. If you  start typing Conn, does Intellisense bring anything up?

As for the filename, you specify the path in relation to your project root. For example, if my project is in directory Foo and my report is in a subfolder called Bar, then my code would be:

report.FileName = Server.MapPath(@"\Foo\Bar\report.rpt");
0
 

Author Comment

by:JDL129
ID: 35138174
brd24gor!!!!!!!!1
Thanks again for hangin' in here with me!!!

I still have a few errors:
SetDBLogonForReport and Server do not exist in the current context.  

Thanks for your help!!
Jerry
0
 
LVL 3

Accepted Solution

by:
brd24gor earned 125 total points
ID: 35138336
That is actually for a website, so if you're doing a Forms app then you can just declare the full path to the report on the hard drive:

report.FileName = @"C:\xxx\xxx\xxx\report.rpt"

As for SetDBLogonForReport, that's the second user-defined procedure in my code sample above. Make sure both procedures, SetDBLogonForReport and ConfigureCrystalReports, are in the same namespace and class. If you are calling them from a different class, then you'll have to declare one or both protected or public.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question