Crystal Reports

  • Thread starter Robert Schuldenfrei
  • Start date
R

Robert Schuldenfrei

Dear NG,

I am just learning object orientated programing in general and C# in
particular.
My first real project is an inventory application using a SQL database. I
have
an item master editor working fine now and it is time to write some paper
reports
from data stored in SQL. I decided to give Crystal Reports a try.

By using the Wizard I have CrystalReport1.rpt sitting as a tab in my
project.
The book that I bought, Using Crystal Reports 10, gives an example in VB:

Dim Report As New ReportDocument
Report.Load("C:\My Reports\Sales.rpt")

What is the equivalent C# execution? I assume that I am going to need a
using statement. The VB Dim statement is probably the C# instantiation.
If I am going to have a path in C# I am probably going to need
double \\ as in: "C:\\My Reports\\Sales.rpt" Am I on the right track or
way off base?

Thinking now about this issue on a higher level, is Crystal Reports the best
way to go? I am an old dude and can code COBOL style reports from scratch.
What about generating text files and just printing them. What is the
procedure
for loading a general Windows printing object? Since reports are likely to
be long, I wish not to display the report on the screen, but generate the
report to a file and then have the user go to the File menu and select
Print File to begin this process.

In this posting I am looking for both direction and some specific C#
statements.

Thanks in advance,

Bob

Robert Schuldenfrei
(e-mail address removed)
 
G

Guest

hi,

don't compare syntatical resemblence. I will explain what is happening
over here.

that vb.net code block try to load a report file to reportdocument object.

I will explaine how it happening in C#.

First you have to riht click your project folder to add an
CrystalReport1.rpt file.
Once you add this .rpt file to your solution it will give a wizard that will
help you out to set the table or dataset(tables).

After successful completion of this (that is adding one .rpt file) you have
to use
crystalReportViewer1 to view the report. This much thing you can achive by
using the .NET IDE or programmatically.
 
R

Robert Schuldenfrei

Hi Sreejith,

Thank you for the information. I am having a little trouble understanding
your answer. Here is my current status:

1/ I have the CrystalReport1.rpt file in my solution.
2/ Unsuccessful in using the CrystalReportViewer as it is "grayed out" in
the Toolbox under Web Forms.
3/ Can not call anything from my code to execute the report. I would think
that there should be a namespace for CR objects and there might be an object
containing a method for viewing the report.
4/ Is CR the best way to write reports?

Cheers,

Bob

Robert Schuldenfrei
(e-mail address removed)
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi again robert,

in addition to the link I sent you I want to let you know that you dont have
to load a report in the code, by default CR create a class derived from
ReportDocument named like your report, you just create an instance of this
report.

Dim Report As New ReportDocument
Report.Load("C:\My Reports\Sales.rpt")

What is the equivalent C# execution? I assume that I am going to need a
using statement. The VB Dim statement is probably the C# instantiation.
If I am going to have a path in C# I am probably going to need
double \\ as in: "C:\\My Reports\\Sales.rpt" Am I on the right track or
way off base?

Thinking now about this issue on a higher level, is Crystal Reports the best
way to go? I am an old dude and can code COBOL style reports from scratch.
What about generating text files and just printing them. What is the
procedure

CR is the way to ge with no doubt, especially in win apps. learn it and it
will make your work a lot more easy.

Cheers,
 
G

Guest

To reply to the part the others did not:

Robert Schuldenfrei said:
Dim Report As New ReportDocument
Report.Load("C:\My Reports\Sales.rpt")

What is the equivalent C# execution?

ReportDocument Report = new ReportDocument();
Report.Load("C:\\My Reports\\Sales.rpt");

Note: Dim Report As NewReportDocument would not work in VB.NET. Anytime you
call a constructor you need open and close parenthesis, even for the default
constructor.

Some good resources for C#:
http://www.c-sharpcorner.com
http://msdn.microsoft.com

Tons of other sites are available, just go to http://www.google.com and type
in C# + .net and you'll get a few thousand results. If you're serious about
learning C# I suggest getting a book to reference.

HTH
 
R

Robert Schuldenfrei

Dear NG,

Thanks for all of your help. I got my first CR report to execute. I now
have to sit down and learn this system. Here is the code that did it:

private void btnCrystal_Click(object sender, System.EventArgs e)
{
ReportDocument report = new ReportDocument();

report.Load("C:\\database\\MCS-3-SQL\\MCS-3inC#\\ItemMaster\\ItemMaster\\Cry
stalReport1.rpt");

report.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.RichText,"C:\\t
mp\\CrystalOut.rtf");
MessageBox.Show("Crystal");
}

Cheers,

Bob
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,
ReportDocument Report = new ReportDocument();
Report.Load("C:\\My Reports\\Sales.rpt");

I strongly recommend not to use this construction, unless that the report
change dynamically, you would have to deal with an extra file on your
instalation as well as make sure that the path is correct,etc

It's MUCH safer to use the class that is created by the CR designer.


Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top