Problem with Crystal Report

V

Victor

Hi, i have a simple report with 1 parameter and i want to send it to
the printer without use the crystalreportviewer but it shows me an
exception "Parameter value is needed",maybe the problem can be in the
way to pass it the parameter.


CrystalReport1 cr = null;
try
{
cr = new CrystalReport1();
cr.FileName="C:\\Proyectos .Net\\crystal\\CrystalReport1.rpt";
cr.Load();

cr.SetParameterValue("person","000002");
cr.PrintOptions.PrinterName = "\\\\ACTEA3\\lj4000";

cr.Refresh();
cr.PrintToPrinter(1,false,0,0);
}

Any idea would be apreciated.
 
I

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

Hi,

IIRC you do not need to load it from File, it's embedded as a resource and
when you instantiate it its load

if you just show it in the screen does it work ok?
do you have a default printer set?, can you just try with it instead of
using a network printer?

the parameter seems to be ok,

If that do not work, what if you use a crystalreportviewer but do not show
it, you load the report, etc but then just print it


cheers,
 
V

Victor

Hi, i tested to show it in the screen and it worked ok,i tested to use
the crystalreportviewer and the parameters worked ok but the problem
was that i can't or i don't find how to specify the printer i want to
use in the crystalreportviewer component, it printed by default printer
on the computer.
 
V

Victor

I have found the solution, here is the code, thanks for the help.

CrystalReport1 cr = null;
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues;
ParameterDiscreteValue crParameterDiscreteValue;

try
{
cr = new CrystalReport1();
cr.FileName = "C:\\Proyectos
..Net\\granitos\\crystal\\CrystalReport1.rpt";

//Get the collection of parameters from the report
crParameterFieldDefinitions = cr.DataDefinition.ParameterFields;

//Access the specified parameter from the collection
crParameterFieldDefinition = crParameterFieldDefinitions["persona"];

//Get the current values from the parameter field. At this point
//there are zero values set.
crParameterValues = crParameterFieldDefinition.CurrentValues;

//Set the current values for the parameter field
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = "000002"; //1st current value

//Add the first current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue);

//All current parameter values must be applied for the parameter field.
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

cr.PrintOptions.PrinterName = "\\\\ACTEA3\\lj4000";
cr.PrintToPrinter(1,false,0,0);
}
 

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