Solved

Crystal Report in C#

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

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now