1

I am making application in ASP.Net 2.0 in VS 2010, i have created crystal report with drag and drop, and its configured from database expert, now my problem is i have two times, start time and end time, i have to fetch the record in between, in short, i have to pass parameters to report and receive, one thing important, i am not using any data set or datatable, everything configured with drag and drop, but on click of button, i dont know what to write to receive parameters in report. Please help!

Muhammad Atif Agha
  • 1,535
  • 3
  • 33
  • 74

2 Answers2

1

Here there is a simple and fast How-To ...

Crystal Report Working with Parameter

This is a working example of how to pass parameter at runtime :

1) Create new Crystal Report Solution

2) Set-up Report with Wizard facility

3) in the Field Exploror add a Field Parameter

4) Right click on the report form and select Step4

5) Select first the field on the database, next the comparision under operators and finally the field parameter. Step5

6) Go to the form and place a textbox with a button.

7) on the button_click paste this code :

 ReportDocument myRpt = new ReportDocument();
 myRpt.Load("**complete path ** \\CrystalReport1.rpt");

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

 crParameterDiscreteValue.Value = textBox1.Text;
 crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
 crParameterFieldDefinition = crParameterFieldDefinitions["codicefiscale"];
 crParameterValues = crParameterFieldDefinition.CurrentValues;

 crParameterValues.Clear();
 crParameterValues.Add(crParameterDiscreteValue);
 crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

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

8) Go back to the form and click on the ReportViewer Object, go to the properties and remove the ReportSource Properties value. (this is setting at runtime)

and the work is done...

Sorry for the indent and the code, but i've made it during the coffee break... have no more time.

For completition i've made this by reading this tutorial

2GDev
  • 2,478
  • 1
  • 20
  • 32
  • I just want to post a parameter from my asp textbox and want to receive in crystal report, this tutorial is about taking a parameter from some alert box or like that, any idea? – Muhammad Atif Agha May 20 '11 at 10:56
  • The Tutorial show you how to pass parameter to Crystal Report... here is another tutorial (http://aspalliance.com/1833_Creating_Parameter_Fields_in_Crystal_Reports) and the parameter is taken from textbox... If you don't like this way i think you have to write some code to achieve what you want – 2GDev May 20 '11 at 11:15
  • i have passed parameter from code to it, and i have configured the report by seeing your above tutorial, but how can i stop from prompting parameter, i want it to work from textbox only. – Muhammad Atif Agha May 20 '11 at 12:10
  • ok but how can i then make it, forexample where AddressID = txtBox.Text; – Muhammad Atif Agha May 20 '11 at 12:56
  • 1
    i have done it, code was very simple ReportDocument report = new ReportDocument(); report.Load(Server.MapPath("CrystalReport2.rpt")); report.FileName = Server.MapPath("CrystalReport2.rpt"); report.SetParameterValue("@h", param.Text); CrystalReportViewer12.ReportSource = report; CrystalReportViewer12.Visible = true; – Muhammad Atif Agha May 20 '11 at 13:33
1

See my question and its answers here Easiest way to pass parameters to Crystal Report from C#?.

Community
  • 1
  • 1
MAW74656
  • 3,449
  • 21
  • 71
  • 118