none
How to load CrytalReport that have Command Table that derived from stored procedure RRS feed

  • Question

  • Hi guys I'am developing a software that simply print a report.

    I'am using Crystal Report IX. In my crystal report i'am using the "Add Command" option to create a table i put my stored procedure in command like in the photo  I create this CrystalReport separated in visual studio.

    My question is how can load this report taht i can supply the parameter of my stored procedure using c# 

    here my stored procedure 

    CREATE PROCEDURE dbo.spRpt_UPAInfo   @upaID INTAS

    this my code in c# 

    private void FRM_ReportViewer_Load(object sender, EventArgs e)
            {
                int param = 7;
    
                ReportDocument crpt = new ReportDocument();
                string rptPath = @"D:\Alvin Files\Script\OwnScripts\UPAScript\UPA_Report\Rpt_Upa.rpt";
                crpt.Load(rptPath);
                crpt_UPA.ReportSource = crpt;
             }

    It load the report but when i change the parameter it cannot dynamically change the data in report

    all reply are really much appreciated 

    thank you in advance




    • Moved by Stanly Fan Friday, September 1, 2017 9:11 AM from windows form general
    Tuesday, August 22, 2017 9:05 AM

All replies

  • The way I handle this is to go get the data myself and present that to the report.

    I then have total control over getting the data and I can use the same data for a datagrid or whatever as well as the report.

    I can use LINQ and chain queries for flexible parameter selection.

    In fact you can substitute a totally different source like a List<t> so long as t has the same columns as your report is designed against.

    eg:

    Say you have a stored proc or table or whatever you design against and it has 3 fields - JobTitle, Gender and HireDate. This is employee data.

    You can do:

                ReportDocument rpt = new  CrystalReport1();
                Person person = new Person
                {
                    JobTitle="Director",
                    Gender="M",
                    HireDate = new DateTime(2015,1,1)
                };
                List<Person> OnePerson = new List<Person>();
                OnePerson.Add(person);
                rpt.SetDataSource(OnePerson);
                crystalReportViewer1.ReportSource = rpt;
                crystalReportViewer1.Refresh();

    If you let crystal go read the data then you need to switch between dev and live databases, it's way harder to do flexible filtering and you don't have that data available.

    Anyhow, there are some crystal types to consider. ReportFields and ReportField. The former is a collection of the latter. A ReportField has values, the simplest is DiscreteValue which is just the one value to match against.

    You put those together something like:

    ReportDocument reportDocument = new ReportDocument();
    ParameterField pField = new ParameterField();
    ParameterFields pFields = new ParameterFields();
    ParameterDiscreteValue pValue = new ParameterDiscreteValue();
    
    pField = "NameOfParameter";
    pValue.Value = "parameterValue";
    pField.CurrentValues.Add(pValue);
    pFields.Add(paramField);
     
    CrystalReportViewer1.ParameterFieldInfo = pFields;

    And of course you have to load your report etc.

    Also

    If you take a look at the properties of your report.

    Does it have "save data with report" checked?

    Uncheck that box.


    Hope that helps.


    • Edited by Andy ONeill Tuesday, August 22, 2017 3:45 PM
    • Proposed as answer by Stanly Fan Monday, August 28, 2017 8:30 AM
    Tuesday, August 22, 2017 10:34 AM
  • Hi TinVin,

    According to your description, your issue is more related about Crystal Reports, it will be more appropriate to ask your question at Crystal Reports Forum.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 30, 2017 8:42 AM