vvka's Collection

Posts Tagged ‘Crystal Reports

Its been 4 days now that I have been juggling with Crystal reports of Visual Studio 2005.

 But all my efforts are been worthwhile since I was able to get the output as desired.

Few things that I learnt are:-

  • Crystal reports without default log on system
  • Crystal reports using parameters through code

[C# CODE]

        protected void btnSearch_Click(object sender, EventArgs e)
        {
           
            CrystalDecisions.Shared.ParameterField PARAMETER_FIELD_Cat = new CrystalDecisions.Shared.ParameterField();
            CrystalDecisions.Shared.ParameterField PARAMETER_FIELD_SKU = new CrystalDecisions.Shared.ParameterField();
           
  
     //Assign the name same as the parameter fields you have created in the report .rpt
            PARAMETER_FIELD_Cat.Name = “ReportParamCatName”;
            PARAMETER_FIELD_SKU.Name = “ReportParamSKUName”;

            CrystalDecisions.Shared.ParameterDiscreteValue PARAMETER_Discrete_FIELD_Cat = new ParameterDiscreteValue();
            CrystalDecisions.Shared.ParameterDiscreteValue PARAMETER_Discrete_FIELD_SKU = new ParameterDiscreteValue();

           
            PARAMETER_Discrete_FIELD_Cat.Value = ddlItems.SelectedItem.Text.ToString();
            PARAMETER_Discrete_FIELD_SKU.Value = ddlSKUs.SelectedItem.Text.ToString();

            PARAMETER_FIELD_Cat.CurrentValues.Add(PARAMETER_Discrete_FIELD_Cat);
            PARAMETER_FIELD_SKU.CurrentValues.Add(PARAMETER_Discrete_FIELD_SKU);
            CrystalDecisions.Shared.ParameterFields PARAMETER_FIELDs = new ParameterFields();

            PARAMETER_FIELDs.Add(PARAMETER_FIELD_Cat);
            PARAMETER_FIELDs.Add(PARAMETER_FIELD_SKU);
           
            CrystalReportViewer1.ParameterFieldInfo = PARAMETER_FIELDs;
            CrystalReportViewer1.EnableParameterPrompt = false;
         

            ////With out log on
            string reportpath = Server.MapPath(“Reports\\RPT_PriceDissemination_Chart.rpt”);

            ReportDocument myreportdocument = new ReportDocument();
            myreportdocument.Load(reportpath);
            myreportdocument.SetDatabaseLogon(“<username>”,”<password>”);

            CrystalReportViewer1.ReportSource = myreportdocument;
            //********

        }

[/CODE]

  • Creating charts
  • Enableing the “Don’t Summarize” check box

 “Don’t Summarize” – works with the formula fields for a chart.

Thus in order to show the data points directly instead of the aggregated functions create a formula field in your .rpt file and assign it the values from the database fields.

For example: –

create a formula like ->

formula = ToNumber ({MyTable.FieldToBeDisplayed})

in

Formula Creation

Once you create a Formula Field, it will then appear in the “Fields Available list”.

chart-expert.jpg

 It will plot the data points of the referd column as it is and will not summarize if you check the “Don’t Summarize” checkbox.

Do let me know if this helps you