CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2013
    Posts
    2

    c# and Crystal Reports with two parameters

    hello everyone,

    I keep trying to pass several parameters to a crystal report, and what happens is the default parameters of the result show instead of my entered parameters.

    Has anyone else had this issue before?

    Chris


    My Code is Below:

    ReportDocument cryRpt = new ReportDocument();
    cryRpt.Load("c:\reports\ReportName+".rpt");

    ConnectionInfo c = new ConnectionInfo();
    c.ServerName = GlobalStorage.Servername;
    c.IntegratedSecurity = true;
    c.DatabaseName = GlobalStorage.DatabaseName;

    CrystalDecisions.CrystalReports.Engine.Tables CrTables = cryRpt.Database.Tables;

    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
    {
    CrystalDecisions.Shared.TableLogOnInfo crtableLogoninfo = CrTable.LogOnInfo;
    crtableLogoninfo.ConnectionInfo = c;
    CrTable.ApplyLogOnInfo(crtableLogoninfo);
    }

    int count = 0;

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


    ParameterFields pfields = new ParameterFields();

    foreach (MyParameter p in parameters)
    {
    ParameterDiscreteValue crtParamDiscreteValue;
    ParameterField crtParamField;
    ParameterFields crtParamFields;

    crtParamDiscreteValue = new ParameterDiscreteValue();
    crtParamField = new ParameterField();
    crtParamFields = new ParameterFields();

    crtParamDiscreteValue.Value = p.parametervalue;
    crtParamField.ParameterFieldName = p.parametername;
    crtParamField.CurrentValues.Add(crtParamDiscreteValue);
    crtParamFields.Add(crtParamField);
    }

    viewer.ParameterFieldInfo = pfields;

    viewer.Refresh();
    viewer.BringToFront();
    viewer.Show();

  2. #2
    Join Date
    Apr 2013
    Posts
    2

    Re: c# and Crystal Reports with two parameters

    i modified my code slightly:

    ReportDocument cryRpt = new ReportDocument();
    cryRpt.Load(@"c:\a1vcr\rs2k\reports\"+ReportName+".rpt");

    ConnectionInfo c = new ConnectionInfo();
    c.ServerName = GlobalStorage.Servername;
    c.IntegratedSecurity = true;
    c.DatabaseName = GlobalStorage.DatabaseName;

    CrystalDecisions.CrystalReports.Engine.Tables CrTables = cryRpt.Database.Tables;

    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
    {
    CrystalDecisions.Shared.TableLogOnInfo crtableLogoninfo = CrTable.LogOnInfo;
    crtableLogoninfo.ConnectionInfo = c;
    CrTable.ApplyLogOnInfo(crtableLogoninfo);
    }

    int count = 0;


    foreach (MyParameter p in parameters)
    {
    cryRpt.SetParameterValue(p.parametername, p.parametervalue);
    }

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

    viewer.BringToFront();
    viewer.Show();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured