.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to pass parameters to crystal reports at runtime while using c#.

Posted By:Shashi Ray       Posted Date: September 01, 2008    Points: 10    Category: ADO.NET    URL: http://www.dotnetspark.com  

How to pass parameters to crystal reports at runtime while using c#. If you take a look at the end of the Page_Load function,
 

If you take a look at the end of the Page_Load function, we have called a method ReportParameter(). This method will actually add/send the parameters to our report.

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
 
public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["aaa"]);
    Class1 dbc = new Class1();

    protected void Page_Load(object sender, EventArgs e)
    {
        CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.ServerName = "nic";
        CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID = "sa";
        CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password = "sa";
        CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName = "abcde";
        ReportParameter();
    }
    private void ReportParameter()
    {
        CrystalReportViewer1.RefreshReport();
        ParameterFields paramFields = new ParameterFields();
        ParameterField pfItemYr = new ParameterField();
        pfItemYr.ParameterFieldName = "year"; //year is Crystal Report Parameter name.
        ParameterDiscreteValue dcItemYr = new ParameterDiscreteValue();
        dcItemYr.Value = DropDownList1.SelectedValue;
        pfItemYr.CurrentValues.Add(dcItemYr);
        paramFields.Add(pfItemYr);
        CrystalReportViewer1.ParameterFieldInfo = paramFields;
    }
}

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

    Read also another Resources from the same Author

Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend