To pass textbox value to crystal report without using database

1. First create a parameter in the paraeterField in the DatabaseFileds, name it crParam.

2. ReportDocument cryRpt = new ReportDocument();

cryRpt.Load(@"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\CrystalReportsWithParam\CrystalReportsWithParam\CrystalReportsWithParam\CrystalReport1.rpt");


ParameterFieldDefinitions crParameterFieldDefinitions ;
ParameterFieldDefinition crParameterFieldDefinition ;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

crParameterDiscreteValue.Value = textBox1.Text;
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields ;
crParameterFieldDefinition = crParameterFieldDefinitions["crParam"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Add(crParameterDiscreteValue);

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();

Now drag and drop that paramter crParam on crystalReport where ever you want to display in.

That's it.

Ebook Download
View all
Learn
View all