Set Parameter in Crystal Reports using ASP.Net

Some one send me a mail and ask for help regarding setting parameters in Crystal Reports using asp.net.

My advice is always to download the web samples at:

Visual Basic .NET Web Samples

C# .NET Web Sample Applications

Then, follow the Readme file to install the “Discrete Parameters” example. This has been my guide, and it works great.

Additional help and tutorials are in the CR SDK:

Crystal Reports .NET SDK – Additional Conceptual Documentation and Tutorials

This file contains additional conceptual information and tutorials for using Crystal Reports in Visual Studio .NET (including a developer reference). This documentation applies to Crystal Reports 9 & 10 and Crystal Reports for Visual Studio .NET 2002 & 2003. Sample applications built using these tutorials are available for download (cr_net_sdk_tutorial_samples_en.zip).

Crystal Reports .NET SDK – Sample Applications from Tutorials

This file contains C# and VB .NET Windows and web sample applications. These samples were built using the tutorials provided in the ‘Crystal Reports .NET SDK – Additional Documentation and Tutorials’ (cr_net_sdk_additional_en.zip). These sample applications applies to: Crystal Reports 9 & 10 and Crystal Reports for Visual Studio .NET 2002 & 2003.

If you’re new to Crystal Reports .NET, get this book:

Crystal Reports .NET Programming

It is both an introduction to Crystal Reports .NET, as well as a object model programming guide/reference. Examples are in both VB.NET and C#.

A number of methods out there use the CrystalReportViewer control to set parameters. That’s great unless you need to export your report to PDF (or XLS or RTF). This is a code snippet I use, it comes from Business Objects tech support:

================================================

rptCount = New ReportDocument
rptCount.Load(Server.MapPath(“reportname.rpt”))
”Get the collection of parameters from the report
crParameterFieldDefinitions = rptCount.DataDefinition.ParameterFields
”Access the specified parameter from the collection
crParameter1 = crParameterFieldDefinitions.Item(“Param1″)
crParameter2 = crParameterFieldDefinitions.Item(“Param2″)

”Get the current values from the parameter field. At this point
”there are zero values set.
crParameter1Values = crParameter1.CurrentValues
crParameter2Values = crParameter2.CurrentValues

”Set the current values for the parameter field
crDiscrete1Value = New ParameterDiscreteValue
crDiscrete1Value.Value = Request.Form(“param1value“)

crDiscrete2Value = New ParameterDiscreteValue
crDiscrete2Value.Value = Request.Form(“param2value“)

”Add the first current value for the parameter field
crParameter1Values.Add(crDiscrete1Value)
crParameter2Values.Add(crDiscrete2Value)

”All current parameter values must be applied for the parameter field.
crParameter1.ApplyCurrentValues(crParameter1Values)
crParameter2.ApplyCurrentValues(crParameter2Values)

=========================================

Once you get used to working with parameters, you can “automagically” display them on your web pages. This series of articles shows you how to get a list of parameters from your report file, and display them on your web form, where you can prompt for inputs:

Automagically displaying a Crystal Reports Parameters – Part I
Automagically displaying a Crystal Reports Parameters – Part II

Support: http://aspadvice.com/blogs/rjdudley/archive/2005/02/21/2554.aspx

You can add comments regarding this article.

Thanks & Regards,
Vijay Modi

Advertisements

About Vijay Modi

Having 12+ years of experience in web application development. Expertise in various domains like E-Commerce, E-Learning, Insurance. I have expertise in web application development, window application development, Performance improvement, bug fixing etc. I am believing in quality work and achieving deadlines. Also like to work on new technologies and quick learner.
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

15 Responses to Set Parameter in Crystal Reports using ASP.Net

  1. josue says:

    Hi, i don’t speak mouch english, my cusestion is,

    how to pass param value of a report to a variable in .net?.

    i need get of values of my params after execute my report?

    plis help me

    THANKS

  2. dfsdcf says:

    lol even i dont spack english orknoe d ans lol

  3. naziboy says:

    cusestion mouch after execute my report?
    plis orknoe

    lol lol lol

  4. naziboy says:

    cusestion mouch after execute my report?
    plis orknoe spack

    lol lol lol

  5. sanjay says:

    How sek flexible hieght of crystal report.
    Please help me

  6. sanjay says:

    How sek flexible hieght of crystal report.
    Please help me .
    i wait

  7. vineet says:

    hi
    i am facing a problem in crystal report
    1-My client is using Crystal Report(RPT File) with Parameters and i am setting runtime default parameters values but still paramertes are prompted with set of text box and submit button
    then it displays report
    how can i fix this.

    • has says:

      how to pass parameters to sql statement?
      select r_object_type,count(r_object_type) as PS_Count from rd_form where form_date>=’parameter1′ AND form_date<='parameter2' group by r_object_type

      note: parameter1 & parameter2 are dates and enetered from the prompt screen

  8. hardik says:

    hi
    vijaybhai thanks for your blogs.

    from
    hardik patel
    kadi

  9. pubby says:

    hiii bro, ….here i was facing da problem frm long time but i dint find solution yet here in my code i hv given credentials even though it ws asking username nn password so avoid it …!!
    protected void btnreport_Click1(object sender, EventArgs e)

    {
    ReportDocument cryRpt = new ReportDocument();
    TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
    TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
    ConnectionInfo crConnectionInfo = new ConnectionInfo();
    cryRpt.Load(Server.MapPath(“final.rpt”));
    crConnectionInfo.ServerName = “DEVELOPMENT2\\MOM2005SRV”;
    crConnectionInfo.DatabaseName = “sampledb”;
    crConnectionInfo.UserID = “guestuser”;
    crConnectionInfo.Password = “guest$ql”;

    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in cryRpt.Database.Tables)
    {
    crtableLogoninfo = CrTable.LogOnInfo;
    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
    CrTable.ApplyLogOnInfo(crtableLogoninfo);
    }

    ParameterFieldDefinitions crParameterFieldDefinitions;
    ParameterFieldDefinition crParameterFieldDefinition;
    ParameterFieldDefinitions crParameterFieldDefinitions1;
    ParameterFieldDefinition crParameterFieldDefinition1;
    ParameterValues crParameterValues = new ParameterValues();
    ParameterValues crParameterValues1 = new ParameterValues();
    ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
    ParameterDiscreteValue crParameterDiscreteValue1 = new ParameterDiscreteValue();

    crParameterDiscreteValue.Value = TextBox1.Text;
    crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
    crParameterFieldDefinition = crParameterFieldDefinitions[“Fromdate”];
    crParameterValues = crParameterFieldDefinition.CurrentValues;

    crParameterDiscreteValue1.Value = TextBox2.Text;
    crParameterFieldDefinitions1 = cryRpt.DataDefinition.ParameterFields;
    crParameterFieldDefinition1 = crParameterFieldDefinitions[“Todate”];
    crParameterValues1 = crParameterFieldDefinition.CurrentValues;

    crParameterValues.Clear();
    crParameterValues.Add(crParameterDiscreteValue);
    crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
    crParameterValues1.Add(crParameterDiscreteValue1);
    crParameterFieldDefinition1.ApplyCurrentValues(crParameterValues1);

    CrystalReportViewer1.ReportSource = cryRpt;
    CrystalReportViewer1.DisplayToolbar = false;
    CrystalReportViewer1.DisplayGroupTree = false;
    CrystalReportViewer1.Visible = true;

    }

  10. jackie says:

    Is there a way to use a variable for the password instead of having the pw hardcoded?

  11. it prompts parameter dialog…

  12. Prashant Tandon says:

    Very informative article!! I really enjoyed it. You made it very simple and understandable. It quite helped me, there are some other articles too which also explained very well about Parameter Field in Crystal Report and helped me lot in completing my task….

    http://www.mindstick.com/Articles/92797a6e-467f-4876-8212-dd8a6c2e3dcc/?Parameter%20Field%20in%20Crystal%20Report

    http://www.c-sharpcorner.com/uploadfile/john_charles/working-with-parameter-fields-in-crystal-reports/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s