• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1205
  • Last Modified:

Crystal Report in C#

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
JDL129
Asked:
JDL129
1 Solution
 
Alpesh PatelAssistant ConsultantCommented:
What you want?
0
 
mlmccCommented:
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
 
brd24gorCommented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
JDL129Author Commented:
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
 
brd24gorCommented:
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
 
JDL129Author Commented:
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
 
brd24gorCommented:
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
 
JDL129Author Commented:
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
 
JDL129Author Commented:
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
 
brd24gorCommented:
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
 
JDL129Author Commented:
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
 
brd24gorCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now