Solved

Crystal Report in C#

Posted on 2011-03-14
12
1,127 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
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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