Creating a very simple report: Crystal Report and SetParameterValue ?

R

Rodo

Hi all,

I'm trying to generate a simple crystal report without a database. Several
people mention the use of a dataset. Someone mention in a msdn forum that I
could use the SetParameterValue to easily fill the fields in a simple
report. So. I looked at datasets and I think I'll try this way first. I'm
pretty new and I still don't understand much of this stuff. So. here is what
I did . and it is not working :-(.

1.-create new windows application: WindowsAppication1.

2.-from the toolbox I add a 'ReportDocument'. This brings up the 'Choose a
ReportDocument" window. There is only one choice in the dropdown box:
'Untyped ReportDocument'. Pressed OK. ReportDocument shows below the form.

3.-Project|add New Item| Crystal Report. CrystalReport1.rpt. This brings up
the 'type of report' window from crystal report. I choose blank report. Then
I add an "unbounded text" field to section 2 (page header) of the report
file. I figure I'll try this with only one field first.

4.-Back to the form[design]. Click on Data source and add a new source.
Options are: Database, web service, object. I picked
object|WindowsAppication1|CrystalReport1. Clicked on the finished button.

5.- I selected the DocumentReport1 icon below the form and change the 'Name'
property to the CrystalReport1 file I created in number 3 above.


The truth is, I don't know what to do in number 4. There are several
choices. I picked Form1 while trying and there isn't any effects I can see.
Now I'm thinking that everything went pretty well, no errors, no warnings !
(It compiles and runs ok). Of course, there is nothing in the form yet. I
added a button and try this:

reportDocument1.SetParameterValue("UnboundString1","abcde");

I get an exception telling me that the index is incorrect. Yeap, I have no
clue why. I guess 'UnboundString1' is not the name of the field. I think I'm
missing something :-( .. Or maybe is a whole bunch :).

I like to be able to
(1) change the value in the text field I created in the .rpt file
(2) and later preview it
(3) and print it.

Could someone point me in the right direction for changing the field through
a button's on_click event. I'll deal with the other two issues later :).

Thanks a bunch.
 
I

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

Hi,

I usually use Dataset to generate reports, I find it easier and more
configurable.

If you want to just generate a simple report you could use only parameters,
I have done this in the past to be able to print a nicely formatted page.

Basically you create your report as you mentioned. After that you add the
parameters you need.

Once the report has all the required parameters you go to code view and code
it like this:

ReportDocument rd = new MyReportName()
rd.SetParameterValue( "param1", value1);
....
rd.SetParameterValue( "paramN", valueN);

//finally assign the report to the viewer
crystalReportViewer1.ReportSource = rd;



Rodo said:
Hi all,

I'm trying to generate a simple crystal report without a database. Several
people mention the use of a dataset. Someone mention in a msdn forum that
I could use the SetParameterValue to easily fill the fields in a simple
report. So. I looked at datasets and I think I'll try this way first. I'm
pretty new and I still don't understand much of this stuff. So. here is
what I did . and it is not working :-(.

1.-create new windows application: WindowsAppication1.

2.-from the toolbox I add a 'ReportDocument'. This brings up the 'Choose a
ReportDocument" window. There is only one choice in the dropdown box:
'Untyped ReportDocument'. Pressed OK. ReportDocument shows below the form.

3.-Project|add New Item| Crystal Report. CrystalReport1.rpt. This brings
up the 'type of report' window from crystal report. I choose blank report.
Then I add an "unbounded text" field to section 2 (page header) of the
report file. I figure I'll try this with only one field first.

4.-Back to the form[design]. Click on Data source and add a new source.
Options are: Database, web service, object. I picked
object|WindowsAppication1|CrystalReport1. Clicked on the finished button.

5.- I selected the DocumentReport1 icon below the form and change the
'Name' property to the CrystalReport1 file I created in number 3 above.


The truth is, I don't know what to do in number 4. There are several
choices. I picked Form1 while trying and there isn't any effects I can
see. Now I'm thinking that everything went pretty well, no errors, no
warnings ! (It compiles and runs ok). Of course, there is nothing in the
form yet. I added a button and try this:

reportDocument1.SetParameterValue("UnboundString1","abcde");

I get an exception telling me that the index is incorrect. Yeap, I have no
clue why. I guess 'UnboundString1' is not the name of the field. I think
I'm missing something :-( .. Or maybe is a whole bunch :).

I like to be able to
(1) change the value in the text field I created in the .rpt file
(2) and later preview it
(3) and print it.

Could someone point me in the right direction for changing the field
through a button's on_click event. I'll deal with the other two issues
later :).

Thanks a bunch.
 

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